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 4 of 10.
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.
Nandkishor said:
10 years ago
int i; is declare as external. Hence for external storage class default value is 0. That is the reason why it prints 0.
Rachit said:
1 decade ago
Please tell me the significance of (int**) because if we write (int) or (int****...) then also the answer is same.
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?.
Ashish said:
1 decade ago
That's because I is declared as a global and and not been initialized. Default value of global variable 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)
Dpol.. said:
1 decade ago
Is I extern variable as extern is not mentioned. It should be automatic according to me? please elaborate.
SREE 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)
Haripriya Joshi said:
1 decade ago
As we all are seeing that i is declared as global and the default initial value of global variable is 0.
Divya said:
8 years ago
Local variable will initialize garbage values, as well as global variables will initialize as 0.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers