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 2 of 3.
Rohit Jindal said:
1 decade ago
How can b return a value because b is a local variable. Value will be lost after returning from function.
Swarnim said:
1 decade ago
In the function b is dead before returning any value. As it is creating problem of memory leak. Then how is a assigned a value 25.
Jyothirmai said:
1 decade ago
In pointers how we differentiate multiplication symbol from pointer symbol.
VIJAY KUMAR said:
1 decade ago
a=**ptr;//a=5;
so
b=(**ptr)*(**ptr);
There are no three astricks the middle one * means multiplication.
b=5*5
b=25 .
so
b=(**ptr)*(**ptr);
There are no three astricks the middle one * means multiplication.
b=5*5
b=25 .
Rupinderjti said:
1 decade ago
The thing here need to take under consideration is that function is being called by reference. So change of value in function definition will appear in main. That's all.
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)
Vasuvandan said:
1 decade ago
What is *ptr here?
Lalit said:
1 decade ago
This answer is wrong because scope of variable b is local in function so this variable automatically remove from memory when function close.
Preethu said:
9 years ago
Thank you @Kavyashree.
Malashree said:
8 years ago
There is no return type no how it is possible to return.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers