C + + pointers, references, and values;

Source: Internet
Author: User

Look directly at the code:

1#include <iostream>2 using namespacestd;3 intAddint*a,int*b) {4     ints;5s = *a + *b;6cout<<"SIG1"<<a<<endl;//a is a pointer, it is an address;7cout<<"Sig2"<<&a<<endl;//&a,& Here is still an access symbol, the address of the address is obtained;8cout<<"Sig3"<<*&a<<endl;//Here I think "*" is the address refers to the content presented, so here is a;9cout<<"SIG4"<<**&a<<endl;//, continue to read the contents of a as an address in memory;Ten     returns; One }  A intMain () { -     intSum,a=1, b=2; -Sum=add (&a,&b);//Why use &a, here "&a" is the address, because the parameters of the add is a pointer, the pointer to point to the address; thecout<<"Sig5"<<&a<<endl;//It is also the one defined in line 13th, so it is the same as the 6th line; -cout<<sum<<endl;//Two values are added to return the value of the int type; -     int*p=&A; -cout<<p<<endl;//assigns the address of a to the pointer p; +cout<<*p<<endl;//The content of the address pointed to by P; -     int&c=a;//Here is the quote, read a blog post on a very good sentence "& is a reference after the type, and the variable is not next to the type is the address. " +cout<<c<<endl;//So here A is C, which is the same block in memory.  A     return 0; at}

Well, that's it. And so on follow-up, encountered problems to add.

C + + pointers, references, and values;

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.