Page 1 of 1

Please explain the execution result of this C Programming code. #include void foo(int a, int b) { a = 10; b = 20; } void

Posted: Fri May 20, 2022 11:47 am
by answerhappygod
Please explain the execution result of this C Programming
code.
#include void foo(int a, int b) { a = 10; b = 20; } void bar(int
*a, int *b) { *a = 10; *b = 20; } int main() { int a = 1, b = 2;
foo(a, b); printf("a: %d; b: %d\n", a, b); a = 1; b = 2;
bar(&a, &b); printf("a: %d; b: %d\n", a, b); a = 1; int c =
a, d = a; foo(c, d); printf("c: %d; d: %d, a: %d\n", c, d, a); c =
a; d = a; bar(&c, &d); printf("c: %d; d: %d, a: %d\n", c,
d, a); a = 1; int *p = &a, *q = &a; bar(p, q); printf("p:
%d; q: %d, a: %d\n", *p, *q, a); return 0; }