Does Lvalue-to-Rvalue conversion occur in function invocation?

前端 未结 1 1877
时光说笑
时光说笑 2021-01-26 19:20

Consider the below code:

#include 
int func(){
   int a = 0;
   return a;
}
int main(){
   int result =         


        
1条回答
  •  遥遥无期
    2021-01-26 20:13

    Yes a undergoes lvalue-to-rvalue conversion as part of initializing the result object . (Informally this means the value stored in the memory location named a is retrieved).

    See [dcl.init]/17.8:

    Otherwise, the initial value of the object being initialized is the (possibly converted) value of the initializer expression. Standard conversions (Clause 7) will be used, if necessary, to convert the initializer expression to the cv-unqualified version of the destination type; no user-defined conversions are considered.

    The Clause 7 includes the lvalue-to-rvalue conversion.

    0 讨论(0)
提交回复
热议问题