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 1 of 3.
Anup kumar said:
4 years ago
How ** ptr represent aa? Explain, please.
(1)
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.
MOUNI said:
7 years ago
Please give the clear description of the answer.
Jay said:
8 years ago
Here, b is local variable, so output can be garbage!
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.
Malashree said:
8 years ago
There is no return type no how it is possible to return.
Preethu said:
9 years ago
Thank you @Kavyashree.
Lalit said:
10 years ago
This answer is wrong because scope of variable b is local in function so this variable automatically remove from memory when function close.
Vasuvandan said:
1 decade ago
What is *ptr here?
Jogamohan Medak said:
1 decade ago
Given a=5;
So, aa=&a;//*aa=*&a=a=5;
//aa contains address of a=1000;
//&aa contains address of 1000 which is
b=**ptr***ptr;
=(**ptr)*(**ptr); //ptr = &aa;*ptr=*&aa=aa;
=(5)*(5); //**ptr=**aa=5 ;
=25;
Ans: [B] 25
So, aa=&a;//*aa=*&a=a=5;
//aa contains address of a=1000;
//&aa contains address of 1000 which is
b=**ptr***ptr;
=(**ptr)*(**ptr); //ptr = &aa;*ptr=*&aa=aa;
=(5)*(5); //**ptr=**aa=5 ;
=25;
Ans: [B] 25
(5)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers