编辑: wtshxd | 2019-07-07 |
return 1;
}If a reference is used for performance in parameters, and will not be changed, using keyword const is recommended (for safe)int f(const int& ri);
#define MAX 5000;
const int MAX = 5000;
const is also recommended to replace the #define macro, for the visibility in symbol table during compiling Reviewing C in C++ (cont.) Overview of the constconst int*p =&i;
int const* p =&i;
int* const p =&i;
const int* const p=&i;
const X& X::clone();
int X::f() const;
Reviewing C in C++ (cont.) class CExap class CExap{public:public:int m_iX;
int m_iX;
CExap v;
CExap* v;
v.m_iX = 0;
v->m_iX = 0;
. is after an object, -> is after a pointer (or iterator) Reviewing C in C++ (cont.) int main(int argc, char* argv[]) {};
argc passes the number of elements in the argv array, argv[] are the character sub-sequences separated by spaces from the command lineargv[
0 ] is the path and program name, the real arguments start from argv[
1 ] Let's compare these #include void main(){ int j;
int v[
5 ] = {1,2,3,4,5}for (j = 0;
j < 5;
j+printf("%d\n", v[ j #include #include using namespace std;
int main(){ vector< int > v;
for (int j = 0;
j < 5;
j+v.push_back(j + 1)for (int j = 0;
j < v.size();
j+cout , cout