What will be the output of the following C program?
int a[] = {11,22,33,44};
int *p = &a[1];
printf("%d", *p);
Options
-
A.
11
-
B.
22
-
C.
33
-
D.
More than one of the above
-
E.
None of the above
Correct Answer (Detailed Explanation is Below)
B.
22
Detailed Explanation
Correct Answer: 22
The expression &a[1] represents the address of the second element of the array.
Therefore, p points to the value 22. Dereferencing the pointer using *p gives the value stored at that address.
Hence the output is 22.
Remember: & obtains an address, while * accesses the value stored at that address.