diff options
| author | Mike Vink <mike@pionative.com> | 2024-06-14 09:23:32 +0200 |
|---|---|---|
| committer | Mike Vink <mike@pionative.com> | 2024-06-14 09:23:32 +0200 |
| commit | 8092f4c334db547ced59d6f439b558dad35e1ab2 (patch) | |
| tree | fa462fa885efea1ec6095d015286998d632c2c3d /3/9_data_structures/42_ace_structure.c | |
| parent | b424517a33bf61aedff29eed74a665402ab496ba (diff) | |
commit for once
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)); +} |
