What's the point of const pointers?

后端 未结 17 1836
粉色の甜心
粉色の甜心 2020-11-30 17:28

I\'m not talking about pointers to const values, but const pointers themselves.

I\'m learning C and C++ beyond the very basic stuff and just until today I realized t

17条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 17:55

    Types of declaring any variables like-
    (1)Declaring a constant variable.
    DataType const varibleName;

     int const x;
        x=4; //you can assign its value only One time
    (2)Declare a pointer to a constant variable
    const dataType* PointerVaribleName=&X;
     const int* ptr = &X;
         //Here pointer variable refer contents of 'X' that is const Such that its cannot be modified
    dataType* const PointerVaribleName=&X;
     int* const ptr = &X;
         //Here pointer variable itself is constant  Such that value of 'X'  can be modified But pointer can't be modified

提交回复
热议问题