References to C + +

Source: Internet
Author: User

  1. int argc, char * argv[]-argument count & argument vector

    ARGC-The number of command-line arguments, argv[] points to each command-line argument, where Argv[0] is the program name: The following program contains the complete program path.

    #include <iostream>intMainintargcChar*argv[]) {     inti =0;//begin with 0       while(I <argc) Std::cout<< argv[i++]//Output String<<" "            //Output SPACE<< Std::endl;//Terminate output line      return 0;}

  2. Reference

    1) as the return value, do not need to produce a temporary object, and then copy the object, (see the code below the comment), currently do not delve into the reference mechanism, now remember to return to the referenced scene: input stream,//Find other additions

    #include <iostream>using namespacestd;int& Rfun (int&);//don ' t dig more,ref func saves time.intFunint);voidMainvoid) {    intA =7, B =9; int&ra = A, &rb = b;//Treat Ra as another name of a    int*pa = &ra, *PB = &RB; cout<< PA <<"  "<< (void*) PA <<Endl; cout<< PB <<"  "<< (void*) PB <<Endl; cout<< a <<"  "<< b <<Endl; cout<< RB <<"  "<< (void*) &AMP;RB << Endl;//&RB = = PB always.RB = Rfun (RA);//B=ra;  Rb=ra;                                                -INT &rd=a; //Rb=fun (RA);cout << RB <<"  "<< (void*) &AMP;RB <<Endl; cout<< a <<"  "<< b <<Endl; RB=8; cout<< a <<"  "<< b <<Endl;}int& Rfun (int&r) {returnR//B=fun (a)--b=a;};intFunintr) {returnR//B=fun (a)--r=a; B=r;};
    2) Reference type parameter

    For parameters of type Class,vector, the reference avoids the value copy, improves efficiency, uses references, functions can change the value of the argument, and if the argument value does not change during the call, the const adornment is added.

//Call by ref can change the value after Func called.#include <iostream>using    namespacestd;voidFUNR (Const int&,int);int& Rfun (Const int&,int);voidMainvoid) {    intA = -; int& B =A; Const  int& c = -; Const int& ca =A; A= $; Const intCB = -; cout<< &a <<"  "<< a <<Endl; cout<< &b <<"  "<< b <<Endl; cout<< &c <<"  "<< C <<Endl; cout<< Endl <<Endl;                           Funr (A, a); //First a,like above;second A, int tmp = A;FUNR (2,2); cout<< Endl <<Endl; int& rf =Rfun (c, c); cout<< &AMP;RF <<"  "<< RF <<Endl;}voidFUNR (Const int& RA,intPA) {cout<< &ra <<"  "<< RA <<Endl; cout<< &pa <<"  "<< PA << Endl;//int tmp = PA, &pa is addr of TMP}int& Rfun (Const int& RA,intPA) {//B = Rfun (RA,PA)-->b = RA    intx = $, &d =x; cout<< &ra <<"  "<< RA <<Endl; cout<< &pa <<"  "<< PA <<Endl; return(int&) RA;}

The above is the current thought of the reference to the Knowledge point summary, previously wrote the topic of the blog post, today to explain more detailed, read the comments, run the program, more quickly understand the citation, VS2015 Community Edition.

References to 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.