#include // malloc, calloc, realloc, free #include // printf int main(int argc, char *argv[]) { int *a = (int *)malloc(1024 * sizeof(int)); printf("a[0] after malloc: 0x%08x\n", a[0]); // undefined a[0] = 0x12345678; printf("a[0] after assignment: 0x%08x\n", a[0]); free(a); printf("a[0] after free: 0x%08x\n", a[0]); // undefined short *b = (short *)malloc(1024 * sizeof(short)); printf("a = %p, b = %p (%s)\n", a, b, (a==b ? "same":"different")); // undefined printf("b[0] after malloc: 0x%04hx\n", b[0]); // undefined b[0] = 0x9abc; printf("b[0] after assignment: 0x%04hx\n", b[0]); printf("a[0] after assignment to b: 0x%08x\n", a[0]); // undefined free(b); printf("b[0] after free: 0x%04hx\n", b[0]); // undefined return 0; }