/* This code CONTAINS ERRORS and CRASHES when run; why it crashes is part of our class discussion when viewing this code */ #include <stdio.h> #include <stdlib.h> unsigned *bigStackArray() { unsigned a[64]; for(int i=0; i<sizeof(a)/sizeof(a[0]); i+=1) { a[i] = 1000 + i; } printf("Big Array:"); for(int i=0; i<6; i+=1) printf(" %d",a[i]); printf(" ..."); for(int i=60; i<64; i+=1) printf(" %d",a[i]); printf("\n"); unsigned *p1 = a; printf("p1 = %p\n", p1); printf("sizeof(a) = %zd\n", sizeof(a)); printf("sizeof(p1) = %zd\n", sizeof(p1)); unsigned *p2 = &a[0]; printf("p2 = %p\n", p2); unsigned *p3 = a + 0; printf("p3 = %p\n", p3); unsigned (*p4)[64] = &a; printf("p4 = %p\n", p4); printf("a = %p\n", a); return a; } void weeStackArray2() { unsigned a[8]; printf("Wee Array 2:"); for(int i=0; i<8; i+=1) printf(" %d",a[i]); printf("\n"); printf("a = %p\n", a); } void weeStackArray() { weeStackArray2(); unsigned a[8]; printf("Wee Array:"); for(int i=0; i<8; i+=1) printf(" %d",a[i]); printf("\n"); printf("a = %p\n", a); } int main(int argc, char *argv[]) { unsigned *x = bigStackArray(); for(int i=0; i<64; i+=1) x[i] += 33000; weeStackArray(); free(x); return 0; }