what does the (int *) do in the following code?
int *ptr = (int *) malloc(10 * sizeof (int));
i’m new to C and i’ve seen the above code with and without the (int *) so im wondering what it does.
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.
That means “cast a
void*pointer into aint*pointer” –malloc()returnsvoid*and you ask the compiler to treat thatvoid*as if it wasint*. This construct aroundmalloc()is only needed in C++ code, and is totally unneeded and even evil in C because it can cause rather subtle yet devastating errors.