C Syntax Explanation

c

Solution

`(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 by `malloc()` to an `int *`, i.e. a pointer to an integer.

This is a very bad usage, and you should not do it.

Problem

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?

Original source

Related problems