Reference topic (cont.) = "constant Reference"

Source: Internet
Author: User

Frequently cited points two points:

1 Initializing a const reference with a variable const int &a = b

2 Use literal constant Initialization Const Reference const int &m = ten;

#include  <iostream>using namespace std;void main () {    //Normal reference     int a = 10;    int &b = a;     printf ("B"%d\n ", b);             / /oft-quoted     int x = 20;    const int &y  = x; //frequently quoted    function: Let variables have   read-only properties  ; that cannot be modified by y  x             //commonly referenced initialization is divided into 2 cases     //(1) with variables   initialization   oft-referenced      {        int x1 = 30;         const int &y1 = x1;//using x1 variable to initialize   constant reference      }        //(2) Literals   initialization   constant reference      {        const int a = 40;         int &m = 41; //General reference   reference a literal   Do you have any memory address for the literal number? Answer: No                        //Compile Error                               const  int &m = 43;//c++ compiler allocates memory space                    }}

3 Const Reference Conclusion:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8C/F6/wKiom1h_Yf2jamUmAAE2ERQUed4997.png "title=" Const references the conclusion. png "alt=" Wkiom1h_yf2jamumaae2erqued4997.png "/>

This article is from the "11907685" blog, please be sure to keep this source http://11917685.blog.51cto.com/11907685/1893026

Reference topic (cont.) = "constant Reference"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.