0% found this document useful (0 votes)
16 views2 pages

Pointers Pseudocodes - 2

The C code initializes an integer variable 'a' to 10 and uses pointers to modify its value. The output of the program is three printed values: 10, 15, and 20, reflecting the changes made through pointer dereferencing. The correct answer is option c) 10, 15, 20.

Uploaded by

anushya.himate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Pointers Pseudocodes - 2

The C code initializes an integer variable 'a' to 10 and uses pointers to modify its value. The output of the program is three printed values: 10, 15, and 20, reflecting the changes made through pointer dereferencing. The correct answer is option c) 10, 15, 20.

Uploaded by

anushya.himate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

What will be the output of the following C code?

#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

Correct Answer: c) 10, 15, 20

You might also like