C Programming - Pointers - Discussion
Discussion Forum : Pointers - Find Output of Program (Q.No. 6)
6.
What will be the output of the program ?
#include<stdio.h>
void fun(void *p);
int i;
int main()
{
void *vptr;
vptr = &i;
fun(vptr);
return 0;
}
void fun(void *p)
{
int **q;
q = (int**)&p;
printf("%d\n", **q);
}
Discussion:
95 comments Page 1 of 10.
Sumit said:
2 decades ago
Please explain, how "0" will be displayed???
Abs said:
1 decade ago
Because i is declared as extern and the default value of an extern variable is 0 ... i think :)
Shashank said:
1 decade ago
The value refer to the pointer p& as the q refer to the extern variable, so the value is 0.
Preethi said:
1 decade ago
What does this line mean actually?.
q = (int**) &p;.
Can anyone explain me please?.
q = (int**) &p;.
Can anyone explain me please?.
Mangesh said:
1 decade ago
Because global veriable is set to 0 (by defult).
Satya RKV said:
1 decade ago
@Mangesh is right.
For preethi answer is &p is nothing but we will get the address of p pointer and we are typecasting to as int multiple indirection.
For preethi answer is &p is nothing but we will get the address of p pointer and we are typecasting to as int multiple indirection.
Kalyan said:
1 decade ago
As p is the void pointer so we have to convert to an integer pointer so we made the conversion. And extern varible default value is 0.
Ch.suresh said:
1 decade ago
I think void *p represent a null pointer so , null pointer means it pointing to null=0.
eg: *p->0(null)
eg: *p->0(null)
Sanjay kr. said:
1 decade ago
I can't understand can any one explain please.
Santhosh said:
1 decade ago
I Can't understand the program. Can anyone explain?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers