- 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;}
- 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*) &RB << Endl;//&RB = = PB always.RB = Rfun (RA);//B=ra; Rb=ra; -INT &rd=a; //Rb=fun (RA);cout << RB <<" "<< (void*) &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 parameterFor 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<< &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 + +