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 3 of 3.

Dinesh said:   1 decade ago
aa=&a//aa contains address of a=1000;
&aa contains address of 1000 which is
any value
so**aa containns 5;
hence **ptr contains 5
and **ptr***ptr=25

Manjunath said:   1 decade ago
You may wonder how is the function power returning an integer even though its prototype is different. In c by default the return type of any function is int.

Kavyashree said:   1 decade ago
aa = &a; // *aa = 5;

**ptr = &aa; ptr is a pointer to a pointer aa.

Hence value stored in a can be accessed using **ptr(which is **ptr = 5).

So the b = **ptr ***ptr means b = 5*5 which is 25.

Uma said:   1 decade ago
Hi i can't understand this program can anybody explain this?

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


Post your comments here:

Your comments will be displayed after verification.