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.
Gireesh said:
1 decade ago
Can anyone tell about void. Actually what is mean by void?
Kapil said:
1 decade ago
Shivam nice explanation.
Krishan said:
1 decade ago
Any pointer can be type-casted to void pointer and void pointer can be type-casted again to any pointer type to operate on the data.
You can say void pointer contains raw data which has no meaning. Typecasting it gives it a proper meaning provided we already know that type of data which it contains.
You can say void pointer contains raw data which has no meaning. Typecasting it gives it a proper meaning provided we already know that type of data which it contains.
Piyush said:
1 decade ago
Hi guys,
Its answer is 0, because I is declare as global. So its by default zero.
Its answer is 0, because I is declare as global. So its by default zero.
Zohra said:
1 decade ago
Well explained. Shivam. Thanks.
Ishwar lal janwa said:
1 decade ago
How come 0 and the fun call & is not define why ?
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.
Rupinderjit said:
1 decade ago
By default the compile initialize the global variable to 0.
Tarun said:
1 decade ago
Thanks shivam for nice explaination.
Ranjeet said:
1 decade ago
Is q and **q are same thing? please tell me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers