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 6 of 10.
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)
HEMANTH said:
1 decade ago
THANKS PRIYA...........
Abhishek shrivastava said:
1 decade ago
Because I is declared as extern, and external variable always will have 0;.
Aneesha said:
1 decade ago
Uninitialized static and extern(global) varibles are by default set to 0.
Tekme2god said:
1 decade ago
I am not clear all about this thing. Please help me.
Sivakumarn said:
1 decade ago
I don't know how integer pointer convert to null pointer any body please can you explain.
Priya said:
1 decade ago
I'll explain d pgm...
p is a void pointer,void pointer implies tat it can point to any type...
q=(int**)&p---->here void pointer(ie.p) is converted to int pointer before assigning it to q,which is an int pointer.
vptr=&i---->here int pointer is assigned to void pointer(ie. vptr),since it can pt any type.
finally q gets value as 0 since i is an extern var,default value is 0.
tats all....
p is a void pointer,void pointer implies tat it can point to any type...
q=(int**)&p---->here void pointer(ie.p) is converted to int pointer before assigning it to q,which is an int pointer.
vptr=&i---->here int pointer is assigned to void pointer(ie. vptr),since it can pt any type.
finally q gets value as 0 since i is an extern var,default value is 0.
tats all....
Pankaj said:
1 decade ago
What a question any one have a answer with exmpl. ?
Mohd kamarshad said:
1 decade ago
Because vptr is voind pointer type it have compatability to convert to any type pointer and i is extern variable which have global access and it's default values is 0
So getting all these thing output would be --> 0
Thanx
So getting all these thing output would be --> 0
Thanx
Adarsh said:
1 decade ago
Thanks to all
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers