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.
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 .
so
b=(**ptr)*(**ptr);
There are no three astricks the middle one * means multiplication.
b=5*5
b=25 .
Jyothirmai said:
1 decade ago
In pointers how we differentiate multiplication symbol from pointer symbol.
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.
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 .
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)
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
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.
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.
Sidra aman said:
1 decade ago
What is the difference between **ptr and ***ptr? please explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers