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.
Suriya said:
1 decade ago
How can I know I is the extern variable or global?
Deepak said:
1 decade ago
(int **) &p. Its type casting of value passed from actual to formal arguments.
As int i is global and value is not assigned so default value is 0.
So 0 is output.
As int i is global and value is not assigned so default value is 0.
So 0 is output.
Sachendra said:
1 decade ago
@Anil ,i we don't declare i as a global then it will print garbage value that is stored in i.
Anil said:
1 decade ago
If we don't declare i as a global, then what will be o/p?
Aadhi said:
1 decade ago
q caries an int value , whereas **q caries address of another pointer.
q=10; //address of q say, 0x44
*p=&q; //value of p=0x44 and its own address say, 0x40
**r=&p; //value of r=0x40
q=10; //address of q say, 0x44
*p=&q; //value of p=0x44 and its own address say, 0x40
**r=&p; //value of r=0x40
Ranjeet said:
1 decade ago
Is q and **q are same thing? please tell me.
Tarun said:
1 decade ago
Thanks shivam for nice explaination.
Rupinderjit said:
1 decade ago
By default the compile initialize the global variable to 0.
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.
Ishwar lal janwa said:
1 decade ago
How come 0 and the fun call & is not define why ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers