Please help with the trace of this code analysis question in C. I already have t
ID: 3770256 • Letter: P
Question
Please help with the trace of this code analysis question in C. I already have the answers but I need help understanding how this code was traced, please explain it.
void test1(int *x)
{
(*x) = (*x)+1; printf(“*x = %d”, (*x));
}
void test2(int y[])
{
y[0] = y[0]+1;
printf(“*y[0] = %d”, (y[0]));
}
void test3(int z)
{
z=z+1;
printf(“z = %d”, (z));
}
int main()
{
int c, *a;
int b[] = {1, 2, 3, 4, 5};
a = &(b[1]);
c = b[0];
test1(a);
test2(b);
test3(c);
printf(“*a = %d, b[0] =%d and c = %d”, (*a), (b[0]), (c)); return 0;
}
3) What is printed as the value of *x when executing the program above?
a)1 b)2 c)3 d)4
4) What is printed as the value of y[0] when executing the program above?
a)1 b)2 c)3 d)4
5) What is printed as the value of z when executing the program above?
a)1 b)2 c)3 d)4
6) What is printed as the value of *a when executing the program above?
a)1b)2 c)3 d)4
7) What is printed as the value of b[0] when executing the program above?
a)1 b)2 c)3 d)4
8) What is printed as the value of c when executing the program above?
a)1 b)2 c)3 d)4
Explanation / Answer
3)
c)3
4)
b)2
5)
b)2
6)
c)3
7)
b)2
8)
a)1