gcc - a classic interview question on C language under Linux
巴扎黑
巴扎黑 2017-06-26 10:59:11
0
2
1000

If you use the GCC compiler to execute the following program under Linux, what is the output result?

#include<stdio.h>
int main(){
    int a=5;
    printf("%d %d %d",a++,a++,++a);
    return 0;
}

The answer is as follows:

In LINUX GCC compiler
7 6 8
In TURBO C
7 6 6

I can understand the answer of 7 6 6, but I really can’t understand why the output of LINUX GCC compiler is 7 6 8. Although I know this is undefiend behavior, I still want to know why the results of 7 6 8 appear.
Original question source: Several classic interview questions in C language under Linux

巴扎黑
巴扎黑

reply all(2)
学习ing

http://blog.csdn.net/laojiu_/...

習慣沉默

In fact, it is because this is undefined behavior that is not in the specification, so the compiler is correct no matter how it calculates it, and it is correct even if the results obtained by the compiler are not uniform.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template