Does variable declaration mean memory allocation?

后端 未结 5 1137
旧时难觅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:48

    from GNU:

    3.2.1 Memory Allocation in C Programs

    Automatic allocation happens when you declare an automatic variable, such as a function argument or a local variable. The space for an automatic variable is allocated when the compound statement containing the declaration is entered, and is freed when that compound statement is exited. In GNU C, the size of the automatic storage can be an expression that varies. In other C implementations, it must be a constant.

提交回复
热议问题