auto,范围for,NULL
- 在c语言中auto表示局部变量
- c++中进行自动类型推导,根据初始化表达式进行推导,相当于类型占位符
1.定义时必须初始化 auto a;(error)
2.auto可以同时定义多个变量,每个表达式的类型必须一致
3.多用于长类型的定义,但不易理解
4.函数参数不能使用auto void fun(auto a,auto b);(error)
5.auto定义指针加不加*都一样 - 范围for (要迭代的变量:迭代的范围),其中范围要明确
- 编译器默认NULL为整数的0,C++中空指针多用nullptr
#include<iostream>
using namespace std;
void test(){
auto a=3;
auto b=4,c=9;
auto pb=&b;
auto& rb=b;
auto rbb=b;
}
void test1(){
int array[]={1,2,3,4,5};
for(auto e:array)
cout<<e<<" ";
cout<<endl;
}
void fun(int a){
cout<<"fun(int)"<<endl;
}
void fun(int* a){
cout<<"fun(int*)"<<endl;
}
int main(){
fun(nullptr);
return 0;
}