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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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; }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply