I wrote the following code for testing the functionality of malloc() .
The Code is compiled using GCC and executed with no errors.
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char *str;
str=(char*)malloc(4*sizeof(char));
printf("Enter string");
gets(str);
if(sizeof(str)>4*sizeof(char))
{printf("Out of Memory");
free(str);
str=NULL;
}
else{
printf("\nsring entered=\n");
while(*str)
{
printf("%c",*str);
str++;
}
free(str);
}
return 0;
}
As i run the above code prints string even greater than 4 bytes long . Please help me with my confusion.