C + + Learning--Reference variables

Source: Internet
Author: User

#include <iostream>using namespacestd;intMain () {//to alias a variable    intA = A; int&c = A;//declare a reference to variable a C, C is an alias for variable A, not the de-address character in the previous section.    The same variable can be multiple references. //the declaration must be initialized when it is referenced, and int &d; is not allowed    intD = C;//references can continue to be referenced. c = -; cout<< a <<Endl; cout<< &a <<' '<< &c <<' '<< &d << Endl;//The address is exactly the same, fully connected to the same block. System ("Pause"); return 0;}

#include <iostream>using namespace std;

intMain () {//a reference to a constant that does not allow modification after a reference Const int&a = A; cout<< a <<Endl; //references to Arrays intarr[ A]; int(&p) [ A] = arr;//Reference typep[2] = -; cout<< arr[2] <<Endl; intarr2[2][3]; int(&AMP;P2) [2][3] =arr2; p2[1][2] =123; cout<< arr2[1][2] <<Endl; //struct Reference type & name = struct instance;//reference to Pointers intx = A; int*point = &x; int* (&y) =Point ; *y = Wu; cout<< *point <<' '<< x <<Endl; System ("Pause"); return 0;}

C + + Learning--Reference variables

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.