C + + Learning 10--exchange

Source: Internet
Author: User

#include <iostream>using namespacestd;//using references is the same space implementationvoidExChange (int&AMP;A1,int&B1) {    intNtemp =A1; A1=B1; B1=ntemp;}//without reference, the new variable has its own space and does not exchange data. voidNotexchange (intA1,intB1) {    intNtemp =A1; A1=B1; B1=ntemp;}//using pointers to implementvoidExchangeb (int*A1,int*B1) {    intntemp = *A1; *A1 = *B1; *B1 =ntemp;}intMain () {intA = A, B = the; cout<<"A:"<< a <<Endl; cout<<"B:"<< b <<Endl; //ExChange (A, b); //Notexchange (A, b);Exchangeb (&a,&b); cout<<"A:"<< a <<Endl; cout<<"B:"<< b <<Endl; System ("Pause"); return 0;}

C + + Learning 10--exchange

Related Article

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.