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 2 of 10.
Saranya.s said:
8 years ago
I am not getting this, anyone please explain clearly.
(1)
Ravi said:
8 years ago
Thank you for all.
Chintan said:
8 years ago
Thank you @Shivam.
Darshan said:
8 years ago
Thank you all for the given explanation.
Manik said:
8 years ago
Here the answer is 0, because 'i' is declared as extern (all the global variables have storage class 'extern'), and all extern variables have an initial value equal to zero.
Divya said:
8 years ago
Local variable will initialize garbage values, as well as global variables will initialize as 0.
Nagma said:
9 years ago
Because 'i' is a global variable not extern.
Manish said:
10 years ago
As 'i' is a global variable whose value is not initialized, so its default value is set to 0.
The pointer q is accessing i it prints 0.
The pointer q is accessing i it prints 0.
PRASHANT SISODIYA said:
10 years ago
Any one tell me why void not convert to int A option is not the answer?
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers