const和指针

来源:互联网 发布:手机淘宝2017正式版 编辑:程序博客网 时间:2024/04/30 00:39
#include <iostream>using namespace std;struct Teacher{    char name[64];    int age;};int operateTeacher(const Teacher* p){    //p->age=10;指针指向的内存空间不能被修改    return 0;}int operateTeacher2( Teacher* const p){    p->age=10;//指针指向的内存空间能被修改    //p = NULL;指针变量本身不能被修改    return 0;}//两者都不能被修改int operateTeacher3( const Teacher* const p){    //p->age=10;//指针指向的内存空间不能被修改    //p = NULL;指针变量本身不能被修改    return 0;}int main(){    system("pause");    return 0;}

0 0
原创粉丝点击