const指针 常指针

(2)常指针

必须进行初始化,且const指针的值不能修改。

#include<iostream>
using namespace std;
int main(){
    const int num=100;
    const  int *ptr=&num; //error! const int* -> int*
    cout<<*ptr<<endl;
}
posted @ 2022-08-19 22:48  luoganttcc  阅读(12)  评论(0)    收藏  举报