Consider the following declaration: int a, *b=&a, **c=&b; The following…
2015
Consider the following declaration:
int a, *b=&a, **c=&b;The following program fragment
a=4;
**c=5;- A.
does not change the value of a
- B.
assigns address of c to a
- C.
assigns the value of b to a
- D.
assigns 5 to a
Attempted by 460 students.
Show answer & explanation
Correct answer: D
First, analyze the pointer declarations. int a declares an integer variable. *b=&a means b is a pointer to the address of a, so b points to a. **c=&b means c is a pointer to the address of b, so c points to b. Following the chain: c -> b -> a.
Next, evaluate the statements. a=4 sets the value of a to 4. Then **c=5 dereferences c to access b, and dereferences b to access a, effectively setting a = 5. Thus, the final value of a is 5.