感觉老师讲得很好,浅显易懂。
#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y=x;
//打印x和y的值
cout<<x<<endl;
cout<<y<<endl;
//修改y的值
y = 10;
//再次打印x和y的值
cout<<x<<","<<y<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y=x;
//打印x和y的值
cout<<x<<endl;
cout<<y<<endl;
//修改y的值
y = 10;
//再次打印x和y的值
cout<<x<<","<<y<<endl;
return 0;
}
//const
#include <iostream>
using namespace std;
int main(void)
{
//定义常量count
const int count = 3;
const int *p =&count;
//打印count次字符串Hello C++
for(int i = 0; i <*p; i++)
{
cout << "Hello imooc" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
//定义常量count
const int count = 3;
const int *p =&count;
//打印count次字符串Hello C++
for(int i = 0; i <*p; i++)
{
cout << "Hello imooc" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y=x;
//打印x和y的值
cout << x <<","<< y <<endl;
//修改y的值
y = 222;
//再次打印x和y的值
cout << x << "," << y << endl;
return 0;
}
using namespace std;
int main(void)
{
int x = 3;
//定义引用,y是x的引用
int &y=x;
//打印x和y的值
cout << x <<","<< y <<endl;
//修改y的值
y = 222;
//再次打印x和y的值
cout << x << "," << y << endl;
return 0;
}