This code:
int p = 10;
void *q;
*q = 10;
Does not compile:
‘=’ : cannot convert from ‘int’ to ‘void *’
However, this code compiles fine:
int p = 10;
void *q;
q = &p;
What is the reason behind it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A
void *points to data of an unknown type (if it is initialized, which yours is not).You can only assign to variables of a known type, or via pointers of a known type.
This converts the
void *into anint *and then assigns a value to that dereferenced integer pointer.