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

Can we declare a function inside a function in c?

0 Answers  


Juxtapose the use of override with new. What is shadowing?

1 Answers  


Explain which function in c can be used to append a string to another string?

0 Answers  


change to postfix a/(b+c*d-e)

8 Answers   Value Labs,


What is Your Name :)

1 Answers  






What are terms in math?

0 Answers  


a=5 a=a++/++a

14 Answers   Bhel,


shorting algorithmS

0 Answers   Wipro,


main() { clrscr(); } clrscr();

6 Answers   ME, Wipro,


Print the foll in C...eg when n=5 the o/p must b + + + + + + + + + + + + + + + + +

1 Answers  


Why can arithmetic operations not be performed on void pointers?

0 Answers  


18)struct base {int a,b; base(); int virtual function1(); } struct derv1:base{ int b,c,d; derv1() int virtual function1(); } struct derv2 : base {int a,e; } base::base() { a=2;b=3; } derv1::derv1(){ b=5; c=10;d=11;} base::function1() {return(100); } derv1::function1() { return(200); } main() base ba; derv1 d1,d2; printf("%d %d",d1.a,d1.b) o/p is a)a=2;b=3; b)a=3; b=2; c)a=5; b=10; d)none 19) for the above program answer the following q's main() base da; derv1 d1; derv2 d2; printf("%d %d %d",da.function1(),d1.function1(),d2.function1 ()); o/p is a)100,200,200; b)200,100,200; c)200,200,100; d)none 20)struct { int x; int y; }abc; you can not access x by the following 1)abc-->x; 2)abc[0]-->x; abc.x; (abc)-->x; a)1,2,3 b)2&3 c)1&2 d)1,3,4

1 Answers  


Categories