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

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

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

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.

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.

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

Sidra aman said:   1 decade ago
What is the difference between **ptr and ***ptr? please explain?

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

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.

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

Bhavya b.c said:   1 decade ago
The variable a contains the value 5 and address of a is 1000;
a=5;
*aa is pointer variable
aa=&a;

So aa contains address of a therefore *aa=5.
when the call statement a=power(&aa) invoked the control transfer to

The formal parameter that is power(int **ptr)
so the value of *aa is assign to the **ptr means **ptr=5.

b=**ptr***ptr;

There are no three astricks the middle one * means multiplication.
b=5*5
b=25 .
(1)


Post your comments here:

Your comments will be displayed after verification.