#include<iostream>
using namespace std;
struct Teacher
{
char name[10];
int age;
};
//指针所指向的内存空间,不能修改
int operatorTeacher01(const Teacher *pT)
{
// pT—>age=10;
return 0;
}
//指针变量本身,不能修改
int operatorTeacher02( Teacher * const pT)
{
//pT—>age=10;
//pT=NULL;
return 0;
}
int operatorTeacher03( const Teacher * const pT)
{
//pT—>age=10;
//pT=NULL;
printf("%d\n",pT->age);
return 0;
}
int main(){
// const int a;
// int const b;//与上相同
// const int *c;//const修饰的是指针所指向的内存空间,不能被修改
// int* const d;//
// const int *const e;
cout<<"hello..."<<endl;
Teacher t1;
t1.age=33;
operatorTeacher03(&t1);
system("pause");
}
1.const是定义常量,意味着只读
#include<iostream>
using namespace std;
int main()
{
const int a=10;
int*p=NULL;
p=(int*)&a;
*p=20;
printf("a:%d\n",a);
system("pause");
}