From 8092f4c334db547ced59d6f439b558dad35e1ab2 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Fri, 14 Jun 2024 09:23:32 +0200 Subject: commit for once --- 3/9_data_structures/42_ace_structure.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 3/9_data_structures/42_ace_structure.c (limited to '3/9_data_structures/42_ace_structure.c') 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 + +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)); +} -- cgit v1.2.3