int* func3() {
//new返回的是该数据类型的指针
int* a = new int(10);
return a;
}
void test02() {
int* arr = new int[10];
for (int i = 0; i < 10; i++) {
arr[i] = i + 100;
}
for (int i = 0; i < 10; i++) {
cout << arr[i] << endl;
}
delete[] arr;
}
//引用作函数的返回值
//1.不要返回局部变量的引用
//int& test03() {
// int a = 10;
// return a;
//}
//2.函数的调用可以作为左值
int& test04() {
static int a = 10;
return a;
}
//c++中一旦发现是引用,就转换为 int* const ref=&a;
void func4(int& ref) {
ref = 100;//ref是引用,转换为*ref=100
}
int func5(int a, int b = 10, int c = 20) {
return a + b + c;
}