#include // 2 points each: What will each of the lines below print? int main(){ int x; printf("Size of x: %d\n", sizeof(x)); printf("Size of &x: %d\n", sizeof(&x)); // Assume x86-64 int *px; printf("Size of px: %d\n", sizeof(px)); // Assume x86-64 again px = &x; printf("Size of *px: %d\n", sizeof(*px)); // Assume x86-64 again printf("Size of *&*&*(&x): %d\n", sizeof(*&*&*(&x))); x = 500; printf("px = %lu (%p)\n", px, px); // This wouldn't be a fair question if(x > px) printf("beep\n"); else printf("click\n"); *px = 600; if(x < *px) printf("beep\n"); else printf("click\n"); if(sizeof(x) == sizeof(*px)) printf("beep\n"); else printf("click\n"); int return_ten(){ return 10; } int (*prt)() = return_ten; printf("sizeof(prt) = %d\n", sizeof(prt)); printf("%p\n", prt); // not a fair question, you can't really know, it'll be kinda big but less than px printf("%d\n", prt()); if(prt == return_ten) printf("beep\n"); else printf("click\n"); int A[10]; int *pA = A; A[5] = 100; printf("pA[5] == %d\n", pA[5]); // This would be ok pA = prt; // This will yield a warning printf("%d\n", ((int (*)())pA)()); // pA[0] = 500; // Why does this cause a problem? // prt(10); int (*return_return_ten())(){ return return_ten; } printf("we got %d\n", return_return_ten()()); if(return_return_ten() == return_ten) printf("beep\n"); else printf("click\n"); int take_return_ten(int (*rt)()){ return rt(); } printf("What this time? %d\n", take_return_ten(return_return_ten())); char s[32]; s[0] = 70; printf("s[0] = %d\n", s[0]); printf("s[0] = %c\n", s[0]); // not as fair, need to remember ASCII table s[0] = 72 + 512; // More CS250 than 430 printf("s[0] = %d\n", s[0]); px = s; px[0] = 0x50505050; // Reminder: 0x50 is 80 in decimal printf("s[0] = %d\n", s[0]); s[4] = 0; printf("%s\n", s); s[0] = 0x70; printf("s[0] = %d\n", s[0] & 0x90); return 0; }