in Programming
496 views
2 votes
2 votes

What will be the output of the following program?

#include <stdio.h>
void f1(int p1, int *p2, int **p3)
{
	p1 = 20;
	*p2 = p1;
	**p3 = *p2;
	p1 = 10; 
}
int main()
{
	int a = 5, b = 5, *c = &b;
	f1(a, &b, &c);
	printf("%d %d %d", a, b, *c);
}
  1. 5 5 5
  2. 5 20 20
  3. 10 20 20
  4. 20 20 20
in Programming
by
496 views

2 Answers

4 votes
4 votes
Best answer
a is called by value so any modification in a will be lost.
b is call also call by value but being a pointer, the dereferenced effect is visible in caller function (call by pointer) so modification will be there.
same for c.

final values of a,b,c are 5,20,20.
selected by

2 Comments

Why the value of b and c is 20,20?
0
0

p1=20

*p2 (is the value of b) =p1 ===> b=20

**p3(is the value of b) = *p2 ===> b=b

note that 'c' is a pointer and *c=b

0
0
1 vote
1 vote

Option b .

Answer:

Related questions