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);
}
5
25
125
Garbage value
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
25 comments Page 2 of 3.

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.

Vasuvandan said:   1 decade ago
What is *ptr here?

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.

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 .

Shailu said:   1 decade ago
I need answer description for this.

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.

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.

Akshay said:   1 decade ago
int(**ptr)
aa=&a,so *aa=5
where ptr=&aa, hence we can say,**&aa.
since, * and & operator cancels each other we are left with
*aa which is 5
hence, 5*5=25

Prakash g said:   1 decade ago
#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);
}

In that **p means value and afre that * is for multification. Again **ptr means values.

So it return directly value ...simple.

Honey said:   1 decade ago
There are no 3 asterisks **ptr * **ptr, here middle *means multiplication.


Post your comments here:

Your comments will be displayed after verification.