//const
#include <iostream>
using namespace std;
int main(void)
{
const int count = 3;
const int *p = &count; /////指针前面要加const
//打印count次字符串Hello C++
for(int i = 0; i < count; i++)
{
cout << "Hello imooc" << endl;
}
return 0;
}
#include <iostream>
using namespace std;
int main(void)
{
const int count = 3;
const int *p = &count; /////指针前面要加const
//打印count次字符串Hello C++
for(int i = 0; i < count; i++)
{
cout << "Hello imooc" << endl;
}
return 0;
}
#include<iostream>
using namespace std;
void fun(int&a, int&b)
{
int c = 0;
c = a;
a = b;
b = c;
}
int main()
{
int x = 10;
int y = 20;
cout << x << "," << y << endl;
fun(x, y);
cout << x << "," << y << endl;
system("pause");
return 0;
}
这样不是更简单了
using namespace std;
void fun(int&a, int&b)
{
int c = 0;
c = a;
a = b;
b = c;
}
int main()
{
int x = 10;
int y = 20;
cout << x << "," << y << endl;
fun(x, y);
cout << x << "," << y << endl;
system("pause");
return 0;
}
这样不是更简单了
2016-03-02
const int *p 与int const *p等价
int *const p
const int x const int *y=&x
int *const p
const int x const int *y=&x
2016-02-25