c++官方文档-按值传递和按引用传递

#include<stdio.h>
#include<iostream>
#include<queue>
#include<map>
#include<memory.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <climits>
#include <sstream>
#include <cstdlib>
using namespace std;

/**
 * Calling a function with parameters taken by value causes copies of the values to be made.
 * This is a relatively inexpensive operation for fundamental types such as int,
 * but if the parameter is of a large compound type,
 * it may result on certain overhead.
 * For example, consider the following function:
 */
/**
 *调用传值函数的时候复制值到函数栈上,这个操作对于基本类型(like int)来说花费很少.
 *但是如果参数大的复合类型,花费就很大,比如下面这个函数.
 *函数的参数是俩个string(按值传递),返回的结果是俩个字符串拼接.
 *按值传递中,复制a和b的内容给函数,如果参数是长的字符串,这意味着调用函数时复制了大量的数据
 */
string concatenate(string a, string b)
{
    return a + b;
}
/**
 * 比较好的方式如下
 * 按引用传递不需要复制数据.函数操作直接在原始字符上(只是给它起了一个别名).
 *顶多这意味着给函数传递某些指针.
 *
 */
string concatenate2(string& a, string& b)
{
    return a + b;
}

/**
 * 按引用传递可能被调用的函数会修改引用的内容,我们可以这样解决
 */
string concatenate3(const string& a,const string& b)
{
    return a+b;
}
/**
 * that for most fundamental types,
 * there is no noticeable difference in efficiency, and in some cases,
 * const references may even be less efficient!
 *
 * 对于基本类型,效率并不会有多大差别,在某些情况下,常量引用可能效率更低
 */

/**
 * 参数的默认值
 */
int divide(int a,int b=2)
{
    int r;
    r = a/b;
    return (r);
}
int main(const int argc, char** argv)
{
    //from cstdlib
    cout<<divide(12)<<endl;
    cout<<divide(20,4)<<endl;
    return EXIT_SUCCESS;
}