What will be output of following program? #include<stdio.h> int main(){ int i…
What will be output of following program?
#include<stdio.h>
int main(){
int i = 3;
int *j;
int **k;
j = &i;
k = &j;
printf("%u %u %u",i,j,k);
return 0;
}
Answer: B. 3 Address Address — Explanation: i is initialized to 3, so the first printed value is the integer 3. j is assigned &i, so printing j prints the address of i (a pointer value). k…
- A.
3 Address 3
- B.
3 Address Address
- C.
3 3 3
- D.
None of above
Attempted by 295 students.
Show answer & explanation
Correct answer: B
Explanation:
i is initialized to 3, so the first printed value is the integer 3.
j is assigned &i, so printing j prints the address of i (a pointer value).
k is assigned &j, so printing k prints the address of j (another pointer value).
Important: The original code calls printf with "%u %u %u" but passes an int and two pointers. This mismatches the format specifiers and causes undefined behavior. Pointer values should be printed with %p and integers with %d.
A portable and correct printf call would be: printf("%d %p %p", i, (void*)j, (void*)k);
Therefore the expected visible output (on most systems) looks like: 3 <address_of_i> <address_of_j>, where the actual address values vary by run and environment.