The 7th chapter of the function--c++ programming module
1. The return type of a function cannot be an array, but it can be any other type, or even a struct and an object. Interestingly, C + + functions cannot directly return an array, but they can be returned as part of a structure or object.
2. Empty brackets in C + + means that the arguments are not indicated. In ANSI C, the parentheses are empty, which means that the arguments are not indicated. In C + +, you should use an ellipsis when you do not specify a parameter list.
void Say_bye (...);
- 3. Array an array the group name is interpreted as the address of its first element there are some exceptions, first, using sizeof with an array name will get the entire length of the array;
4. In C + +, when and only if int *arr and int arr[] are used in function headers or function prototypes, they all mean the same meaning that arr is an int pointer.
5. Protect the array with const: To prevent the function from inadvertently modifying the contents of the array, you can use the keyword const when declaring the parameter, void Show_array (const double ar[], int n);
C + + declares const double ar[] interpreted as const double *ar.
6. If the data type itself is not a pointer, you can assign the address of the const data or non-const data to a pointer to const, but only the address of the non-const data to the non-const pointer.
7. Use const as much as possible, and declare pointer arguments as pointers to constant data for two reasons: first, you can avoid programming errors that result from inadvertently modifying data, and secondly, using const allows a function to handle both const and non-const arguments, otherwise it will only accept non-const data.
8. int age = 39;
const int *PT = &age;
The PT declaration does not imply that the value it points to is a constant, but only means that the value is a yield for pt. In other words, you can modify the value of age directly from the age variable, but you cannot use the PT pointer to modify it.
9. int data[3][4];
int total = SUM (data, 3);
Data is an array name, and the array name is the address of the first element of the array, which has 3 elements, each of which is an array of 4 int values, so the type of data is a pointer to an array of 4 int.
int sum (int (*AR2) [4], int size);
int sum (int ar2[][4], int size);
The code for sum does not use const when declaring parameter AR2, because this technique can only be used for pointers to basic types, and AR2 is a pointer to pointers.
10. The address of the function is the start address of the memory where the machine language code is stored.
Auto Automatic type inference can only be used for single-value initialization, not for initialization lists. P245
12. Use typedef to simplify complex declarations. P248
C + + Primer Plus reading notes--7th chapter of the programming module of function--c++