标签:namespace main 其他 code amp 地址 erro cout 修改
int const x = 3;
const int x = 3;
int* const p = &array
: 指针p不能够指向其他地址const int* p = &array
: 指针p只读&array
,不能够对其进行修改举例,
#include <iostream>
using namespace std;
int main()
{
int arr[3]={1,2,3};
int varr[3]={100,200,300};
const int* p1 = arr;
int* const p2 = arr;
cout << *p1 << endl;
cout << *p2 << endl;
// *p1 = 22; // error
*p2 = 22;
cout << *p2 << endl;
cout << arr[0] << endl;
p1 = varr;
cout << *p1 << endl;
p2 = varr;//error
return 0;
}
标签:namespace main 其他 code amp 地址 erro cout 修改
原文地址:https://www.cnblogs.com/yaos/p/12099521.html