指針指向const修飾的變量時,應(yīng)該是const int const *p = &a;
不應(yīng)該是const int * const p = &a;么?
答案有錯吧?
不應(yīng)該是const int * const p = &a;么?
答案有錯吧?
2016-03-06
//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
無實(shí)參則用默認(rèn)值,有實(shí)參則用實(shí)參
內(nèi)聯(lián)函數(shù)用inline標(biāo)識
內(nèi)聯(lián)函數(shù)與宏相似
內(nèi)聯(lián)函數(shù)用inline標(biāo)識
內(nèi)聯(lián)函數(shù)與宏相似
2016-02-25
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