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

后端 未结 9 1136
你的背包
你的背包 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:32

    Sizeof analyzes the passed expression to find its type. It then returns the size of the type.

    Because the size of a type is always known at compile time, it is put into the machine code as a constant.

提交回复
热议问题