what is void pointer?



what is void pointer?..

Answer / himaja

pointers can also be declared as void type.void pointers cant be dereferenced without explict type conversion,this is becoz being void the compiler cnt determine the size of object that pointer points to,though void vaariables declared is not allowed,thus void p displays error msg "size of p is unknown or 0" after compilation
#include<stdio.h>
int p;
float d;
char c;
void *pt=&p;
void main(void)
{
clrscr();
*(int*)pt=12;
printf("\n p=%d",p);
pt=&d; /*pt points to d*/
*(float*)pt=5.4;
printf("\n r=%f",d);
pt=&c; /*pt points to c*/
*(char*)pt=H;
printf("\n c=%c",c);


o/p:
P=12
R=5.4
C=H

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More C Interview Questions

the question is that what you have been doing all these periods (one year gap)

1 Answers   HCL,


how would a 4*3 array A[4][3] stored in Row Major Order?

0 Answers   HCL, Ignou,


What is volatile variable how do you declare it?

1 Answers  


hi how to convert program from notepad to turboc editor can u please help me

3 Answers  


What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) main(); }

4 Answers   Infosys, TCS,


who did come first hen or agg

15 Answers   Infosys,


how to find your architecture is LittleEndian or BigEndian?

1 Answers  


Why can't I perform arithmetic on a void* pointer?

1 Answers  


Is main() is used in the program,,see below example? void main() { int i; for(i=0;i<10;i++) main(); } Then what is the output of the program?

6 Answers  


How many levels of pointers have?

1 Answers  


the expression a=30*1000+2768; evalutes to a) 32768 b) -32768 c) 113040 d) 0

1 Answers  


int x=sizeof(!5.856); What will value of variable x?

2 Answers  


Categories