What is a reference variable in C++?

后端 未结 12 2310
孤城傲影
孤城傲影 2020-11-22 08:41

What would be a brief definition of a reference variable in C++?

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 09:25

    A reference variable provides an alias (alternative name) for a previously defined variable. For example:

    float total=100;
    float &sum = total;
    

    It means both total and sum are the same variables.

    cout<< total;
    cout << sum;
    

    Both are going to give the same value, 100. Here the & operator is not the address operator; float & means a reference to float.

提交回复
热议问题