添加循环for的demo

This commit is contained in:
zhuyijun 2021-08-07 23:58:51 +08:00
parent f11b43f9ff
commit 98e8d6c74b

36
base/fortest.cpp Normal file
View File

@ -0,0 +1,36 @@
//
// Created by nicemoe on 2021/8/7.
//
#include <iostream>
using namespace std;
int main()
{
double m[5] = {3.1, 4.5, 6.3, 7.6, 1.4};
//x是值复制 无法修改m数组
for (double x : m)
{
x++;
}
for (double x : m)
{
cout << x << "\t";
}
cout << endl;
//&x是引用可以真正修改m数组
for (double &x : m)
{
x++;
}
cout << endl;
for (double x : m)
{
cout << x << "\t";
}
cout << endl;
return 0;
}