The
malloc()
function returns a pointer to the allocated memory as a
void*
which must be cast (by you) to the appropriate type. You need to change your code thus, in order to let the compiler know that you understand what you are doing:
x = (int*)malloc (sizeof(int));
[edit by AH]
The reason
malloc()
returns a
void*
is because its a generic call to allocate memory in bytes. Why generic? So it can be used to allocate memory for any type of data (characters, integers, double, structures, anything really).
[/edit]