ポインタの const 制約

  1. int  x, y;
  2. int  *  const  ptr = &x; //ptr は整数への定数ポインタです
  3.                       //整数は ptr を通じて変更できます。
  4.                       //ただし、ptr は常に同じメモリを指します
  5.                       //位置。
  6. *ptr = 7;    //正しい
  7. ptr = &y;    //エラー

 

  1. int  x=5, y;
  2. const  int  * const  ptr = &x;  //ptr は、オブジェクトへの定数ポインタです。
  3.                             //定数の整数。常にptr
  4.                             //同じ場所を指します
  5.                             //そしてその位置の整数
  6.                             //変更できません。

おすすめ

転載: blog.csdn.net/leon_founder/article/details/2782481