
Looking at this piece of code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct _point{
int x;
int y;
} point;
int main (void)
{
point *ptr;
point obj;
ptr = (point *)malloc(sizeof(char));
obj.x = 500;
obj.y = 5000;
memcpy((void *)ptr, (void *)&obj, sizeof(point));
printf("point.x = %d, point.y = %d\n", ptr->x, ptr->y);
return 0;
}
Why is it running correctly when I run it. Shouldn't I get a segfault given I incorrectly do malloc() on sizeof(char) instead of sizeof(point)?