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 9 of 10.

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.

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

Zohra said:   1 decade ago
Well explained. Shivam. Thanks.

Piyush said:   1 decade ago
Hi guys,

Its answer is 0, because I is declare as global. So its by default zero.

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.

Kapil said:   1 decade ago
Shivam nice explanation.

Gireesh said:   1 decade ago
Can anyone tell about void. Actually what is mean by void?


Post your comments here:

Your comments will be displayed after verification.