diff options
Diffstat (limited to '3/9_data_structures/42_ace_structure.c')
| -rw-r--r-- | 3/9_data_structures/42_ace_structure.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/3/9_data_structures/42_ace_structure.c b/3/9_data_structures/42_ace_structure.c new file mode 100644 index 0000000..8b4e92d --- /dev/null +++ b/3/9_data_structures/42_ace_structure.c @@ -0,0 +1,23 @@ +#include <stdio.h> + +struct ACE { + short v; + struct ACE *p; +}; + +// B. it's a linked list of short values that are multiplied. +short test(struct ACE *ptr) { + short v = 1; + while (ptr) { + v *= ptr->v; + ptr = ptr->p; + } + return v; +} + +int main(void) { + struct ACE a = {2, NULL}; + struct ACE b = {3, NULL}; + a.p = &b; + printf("%d\n", test(&a)); +} |
