Does variable declaration mean memory allocation?

后端 未结 5 1106
旧时难觅i
旧时难觅i 2020-12-29 07:05

Will it be precise to say that in

void f() {
    int x;
    ...
}

\"int x;\" means allocating sizeof(int) bytes o

5条回答
  •  别那么骄傲
    2020-12-29 07:41

    It depends on a lot of factor. The compiler can optimize and remove it from the stack, keeping the value in register. etc.

    If you compile in debug it certainly does allocate some space in the stack but you never know. This is not specify. The only thing specify is the visibility of the variable and the size and arithmetic on it. Look at the C99 spec for more information.

提交回复
热议问题