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

Sravanthi said:   1 decade ago
I didn't understand where variable i is declared as extern can any one tell me?

Sunil said:   1 decade ago
i is declare as global variable & default value of global variable is 0.

Abhishek shrivastava said:   1 decade ago
Because I is declared as extern, and external variable always will have 0;.

Aneesha said:   1 decade ago
Uninitialized static and extern(global) varibles are by default set to 0.

Kowsik said:   8 years ago
What will be output of program if 'i' is initialised globally as int i=5?

PRASHANT SISODIYA said:   10 years ago
Any one tell me why void not convert to int A option is not the answer?

Mohamed mohsen said:   1 decade ago
Because i is global variable by default compiler initialize it to zero.

Seema said:   1 decade ago
As i is declared global and default value of global variables is 0.

Prasun said:   1 decade ago
By default the global variable has default value 0. So answer is 0.

Venky said:   1 decade ago
@Geetha void function () means the function returns nothing not 0.


Post your comments here:

Your comments will be displayed after verification.