Consider the below code snippet:
#include <stdio.h>
int main()
{
int p = malloc( sizeof( int ) );
return 0;
}
The above program compiles successfully without any warning.
Shouldn't it give error/warning as address of memory chunk is being stored in integer variable
rather than a pointer?
Initially, i believed that the behavior is strange because i forgot to include stdlib
.
Soon, my assumption failed. The behavior is same even after including stdlib
.
See the below program after including stdlib
#include <stdio.h>
#include <stdlib.h>
int main()
{
int p = malloc( sizeof( int ) );
return 0;
}
This program has also the similar behavior.
Why it compiles successfully?