Conflict between a Stanford tutorial and GCC

前端 未结 5 1915
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 18:58

According to this movie (around minute 38), if I have two functions with the same local vars, they will use the same space. So the following program, should print 5

5条回答
  •  执笔经年
    2020-12-12 19:13

    In the function A, the variable a is not initialized, printing its value leads to undefined behavior.

    In some compiler, the variable a in A and a in B are in the same address, so it may print 5, but again, you can't rely on undefined behavior.

提交回复
热议问题