- Reference provide a convenient alternative to pointers for processing large structures with a function, and they are essential for designing classes.
- You might recall that C and C++ use the & symbol to indicate the address of a variable. C++ assigns an additional meaning to the & symbol and presses it into service for declaring reference variables.
- The typical use for a reference variable is as a function parameter, particularly for structure and object arguments.
- * 和 &的使用方法类似,类型修饰符的优先级高于变量名。
- int * a = NULL; //此时*与int结合,表明a是一个指针变量;
- int & b = a; //此时&与int结合,表明b是a的引用变量;
- int c = 0; a = &c; //此时&与c结合,是取地址符;
- int d = *a; //此时*与a结合,是取值运算符。