767 views
4 votes
4 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

2 Answers

Best answer
3 votes
3 votes
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
Answer:

Related questions

6 votes
6 votes
2 answers
1
Arjun asked Oct 18, 2016
627 views
What is the output of this program?#include <stdio.h int main() { char *ptr; char string[] = "Hello 2017"; ptr = string; ptr += 4; printf("%s",++ptr); }Hello 2017ello 201...
3 votes
3 votes
2 answers
4