#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int main()
{
int array[] = { 1,2,3,4,5,6,6,4 };
//范围for——语法糖
//自动依次取数组中数据赋值给e对象,自动判断结束
for (auto x : array)
{
cout << x << " ";
}
cout << endl;
return 0;
}
【注意事项】
1.auto不能作为函数的参数
void TestAuto(auto a)
{}
2.auto不能直接用来声明函数
void TestAuto()
{
int a[]={1,2,3};
auto b[] = {4,5,6};
}