函数的默认参数 返回值类型 函数名(参数=默认值){} #include <iostream> using namespace std; int func(int a = 10, int b = 10) { return a + b; } int main() { int a = func(20,30); cout << a << endl; system("pause"); } 没有用默认值,有的话用输入值. 注意: 1. 如果某个位置参数有默认值
vector 的size函数返回vector大小,返回值类型为size_type,Member type size_type is an unsigned integral type,即无符号整数: vector<int> A; A.size()-1因为size返回值是无符号类型所以 A.size()-1越界,是个很大的数 正确使用 (int) (A.size()-1)