The substance of references in C + +

Source: Internet
Author: User

A C + + reference is the pointer has an address. Just optimize.

// ConsoleApplication4.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"int main(){    //char c = ‘a‘;    //printf("%c",(&c)[10]);    //上次没打印成功题    //以变量地址后数10个字节当成字符打印    //刚才忘说了..    /*    引用真的没有地址么    */    int Temp = 10;    int *p1 = &Temp;    int Temp2 = 20;    int &p2 = Temp2;    int *p = (&Temp2) -3;    printf("%d",*(int*)*p);    /*        int Temp = 10;013A17B8  mov         dword ptr [Temp],0Ah      int *p1 = &Temp;013A17BF  lea         eax,[Temp]  013A17C2  mov         dword ptr [p1],eax      int Temp2 = 20;013A17C5  mov         dword ptr [Temp2],14h      int &p2 = Temp2;013A17CC  lea         eax,[Temp2]  013A17CF  mov         dword ptr [p2],eax      */    /*    引用就是编译器做限制的指针    引动的地址对使用者是隐藏的    指针比较灵活,操作失误可能会产生严重后果,    C++推荐使用引用    */    return 0;}

The substance of references in C + +

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.