void pointers and arrays
1 Answer
void pointers and arrays
| Flag | PURGE
void *c;
c=(void *)malloc(sizeof(float)*400);
now as c is a void pointer pointing to a memory block of said size.
Now the block so pointed will contain garbage , and can be treated as an array:
So if I want to print/access all the values so stored as float , how can I do it?
I have tried normal access thru pointers and loops and it throws an error "void is not a pointer to object type"...
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
Email me when people comment.
Email me when people comment.
Loading...
An error occurred in subscribing you.
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
void pointers can hold address of any type of variables.But when we try to access using void pointer(*c as you mentioned) derefference operator will point to data type of pointer.
- sud8640 February 11, 2014so only the error.
example:{{void *c;float size[10];c=&size;
printf("%f",*c);
this printf statement will give u error beacuse of above reason.