/*
Can you interchange the execution order of the printf() statements?!
Notes:
- problem occurs in 32-bit Ubuntu 14.04
- problem occurs in 64-bit Ubuntu 14.04
*/
#include <stdio.h>
int * addition(int a, int b) {
int c = a + b;
int *d = &c;
return d;
}
int main(void) {
int result = *(addition(1, 2));
int *result_ptr = addition(1, 2);
printf("result = %d\n", *result_ptr);
printf("result = %d\n", result);
return 0;
}
The question says that exchanging order of lines
printf("result = %d\n", *result_ptr);
and
printf("result = %d\n", result);
will result in different output. But when I compiled and run both codes in Ubuntu the results are the same, both output is 3 3. The problem is suppose to happen in Ubuntu only.