C the same global variable defined in different files

前端 未结 6 949
我在风中等你
我在风中等你 2020-12-04 17:09

I am reading this code from here(in Chinese). There is one piece of code about testing global variable in C. The variable a has been defined in the file t

6条回答
  •  温柔的废话
    2020-12-04 17:48

    b has the same address because the linker decided to resolve the conflict for you.

    sizeof shows different values because sizeof is evaluated at compile time. At this stage, the compiler only knows about one b (the one defined in the current file).

提交回复
热议问题