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);
}
Error: cannot convert from void** to int**
Garbage value
0
No output
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
95 comments Page 10 of 10.

Mangesh said:   1 decade ago
Because global veriable is set to 0 (by defult).

Preethi said:   1 decade ago
What does this line mean actually?.

q = (int**) &p;.

Can anyone explain me please?.

Shashank said:   1 decade ago
The value refer to the pointer p& as the q refer to the extern variable, so the value is 0.

Abs said:   1 decade ago
Because i is declared as extern and the default value of an extern variable is 0 ... i think :)

Sumit said:   2 decades ago
Please explain, how "0" will be displayed???


Post your comments here:

Your comments will be displayed after verification.