I am studying C Language I need some explanation about a code segments,
int *p;
p = (int *) malloc(sizeof(int));
What does the (int *) means and whats really happening when you execute the above Code?
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.
(int *)is a so called cast operator. It is used to convert the value on the right side of the operator to the type enclosed in parenthesis.Here, it is used to convert the
void *pointer returned bymalloc()to anint *, i.e. a pointer to an integer.This is a very bad usage, and you should not do it.