Consider the following piece of C code #include <stdio.h> int a; void f(int x, i
ID: 3762429 • Letter: C
Question
Consider the following piece of C code
#include <stdio.h>
int a;
void f(int x, int y, int z) {
int b;
x = x+1;
y = y+1;
b = x+y;
z = z+1;
a = b;
}
int main() {
int b = 1;
int c[3] = {0,0,0};
{
int a = 0;
f(a,b,c[b]);
}
printf("%d ", a);
printf("%d ", b);
printf("%d ", c[0]);
printf("%d ", c[1]);
printf("%d ", c[2]);
return 0;
}
a) What is the output of this program if parameters are passed by value?
b) What is the output of this program if parameters are passed by reference?
c) What is the output of this program if parameters are passed by name?
Explanation / Answer
a. Output:
3
1
0
0
0
b. Output:
3
2
0
1
0
c. Output:
3
2
0
1
0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.