CPlusPlusThings icon indicating copy to clipboard operation
CPlusPlusThings copied to clipboard

const-5-(2)

Open Zongshichao opened this issue 1 year ago • 1 comments

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

#include<iostream> using namespace std; int main(){ int num=0; int * const ptr=&num; //const指针必须初始化!且const指针的值不能修改 int * t = &num; *t = 1; cout<<*ptr<<endl; } 这里const指针是可以直接修改值的,只是指向不可以改,不需要通过另外的指针修改吧?

Zongshichao avatar Apr 12 '23 02:04 Zongshichao

Hye Assigned me this issue want to work on issue

shraddha761 avatar Apr 12 '23 09:04 shraddha761

@Zongshichao 这里 const指针的值 指的是const指针的指向吧,不过这段话确实容易引起误会

laialaodi avatar Apr 17 '23 12:04 laialaodi

确实,应该是const指针的指向不能修改,值是可以修改的,这里可能表达不清楚

JKYovo avatar Apr 17 '23 14:04 JKYovo

那我把原文改一改吧

laialaodi avatar Apr 24 '23 10:04 laialaodi