what's the mechanism of sizeof() in C/C++?

后端 未结 9 1143
你的背包
你的背包 2020-12-09 13:16

It seems sizeof is not a real function?

for example, if you write like this:

int i=0;
printf(\"%d\\n\", sizeof(++i));
printf(\"%d\\n\", i);
         


        
9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 13:30

    It is replaced with the constant (4 in your case) at compile time. Because it takes 4 bytes to hold an int on your platform.

    And your code will not compile, instead of giving you any output ;-) Because of sizoef ;-)

提交回复
热议问题