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 5 of 10.
Abs said:
1 decade ago
Because i is declared as extern and the default value of an extern variable is 0 ... i think :)
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.
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.
Sivakumarn said:
1 decade ago
I don't know how integer pointer convert to null pointer any body please can you explain.
Indira said:
1 decade ago
Can anyone tell me?
q = (int**)&p = q = (int)&p.
What is the use of (int**).
q = (int**)&p = q = (int)&p.
What is the use of (int**).
Paddu said:
1 decade ago
Answer is 0 because i is external variable.
Default value of external variable is 0.
Default value of external variable is 0.
Kalyan kedarnath said:
5 years ago
q=(int**)&p // Typecasting.
i initial value is Zero 0 because Global variable.
i initial value is Zero 0 because Global variable.
(1)
Piyush said:
1 decade ago
Hi guys,
Its answer is 0, because I is declare as global. So its by default zero.
Its answer is 0, because I is declare as global. So its by default zero.
Maheswari said:
8 years ago
If we initialized i=5 it will print 5. Whatever I value it will print that value.
Annapurna said:
1 decade ago
Can we declare void as a datatype for parameters and how the compiler treats it?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers