添加循环for的demo
This commit is contained in:
parent
f11b43f9ff
commit
98e8d6c74b
36
base/fortest.cpp
Normal file
36
base/fortest.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user