Pointers Pseudocodes - 2
Pointers Pseudocodes - 2
#include <stdio.h>
int main() {
int a = 10;
int *p, **q;
p = &a;
q = &p;
printf("%d\n", a);
*p = 15;
printf("%d\n", a);
**q = 20;
printf("%d\n", a);
return 0;
}
Options:
a) 20, 20.20
b) 10, 15, 10
c) 10, 15, 20
d) 15, 20, 20
Explanation
1. Initialization:
● The integer variable a is initialized to 10.
● A pointer p is declared and assigned the address of a.
● A double pointer q is declared and assigned the address of p.
2. First Output:
● The first printf statement prints the value of a, which is 10.
3. Modification through Pointer:
● The statement *p = 15; changes the value of a to 15 (since *p
dereferences p, pointing to a).
4. Second Output:
● The second printf statement prints the updated value of a, which is now
15.
5. Modification through Double Pointer:
● The statement **q = 20; changes the value of a to 20 (since **q
dereferences q to get to p, and then dereferences p to access and modify
a).
6. Third Output:
● The third printf statement prints the final value of a, which is now 20.
Final Output
The printed output from this code will be:
10
15
20