1

我有一个非常简短(而且几乎是菜鸟)的问题。我有一个功能,包括:

void function(int x)
{
    x = 3;
    if (x == 4)
        printf("HI!");
    x = 4;
}

HI!会打印单词吗?换句话说,一个 C 程序是按顺序读取的吗?

非常感谢!

4

2 回答 2

1

No, the code compiles to a sequence of instructions which happen sequentially one after the other. The comparison to 4 will always before the assignment x = 4. So it will be false.

This type of order is guaranteed when you are dealing with a single thread. When you have multiple threads you can get strange results and race-conditions unless you are careful.

于 2013-06-25T00:30:30.787 回答
0

It will not be printed. The line above is what matters of course.

于 2013-06-25T00:29:27.680 回答