编译器是否调整int大小?

ddl*_*ddl 1 c++ int types

我想知道在这种情况下,compiller会将int变量大小调整到最大可能值吗?或者它会使用整个32位int?

pseudocode:

int func()
{
    if (statement)
        return 10;
    else if (statement2)
        return 50;
    else
        return 100;
}

// how much memory will be alocated as it needs only 1 byte?
Run Code Online (Sandbox Code Playgroud)

小智 7

函数返回int,分配的内存将是sizeof(int),无论存储在其中的实际值如何.