C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 19)
19.
What will be the output of the program ?
#include<stdio.h>
power(int**);
int main()
{
int a=5, *aa; /* Address of 'a' is 1000 */
aa = &a;
a = power(&aa);
printf("%d\n", a);
return 0;
}
power(int **ptr)
{
int b;
b = **ptr***ptr;
return (b);
}
Discussion:
25 comments Page 3 of 3.
Kishie said:
8 years ago
b will be 25;
The program should cry with an error about the return type of the function prototype.
The program should cry with an error about the return type of the function prototype.
Jay said:
8 years ago
Here, b is local variable, so output can be garbage!
MOUNI said:
7 years ago
Please give the clear description of the answer.
Deepak said:
7 years ago
@All.
Let us consider that a=5.aa=&a i.e, if a is storing at 500th location, means aa=500 and as we can see in the above prog that we are sending the address of pointer in function call i.e suppose to consider the address of pointer is 600 i.e &aa=600 so in order to access to value i=5 we dereference it by two times hence they have used **ptr.
Let us consider that a=5.aa=&a i.e, if a is storing at 500th location, means aa=500 and as we can see in the above prog that we are sending the address of pointer in function call i.e suppose to consider the address of pointer is 600 i.e &aa=600 so in order to access to value i=5 we dereference it by two times hence they have used **ptr.
Anup kumar said:
4 years ago
How ** ptr represent aa? Explain, please.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers