[C++] c pointer

  • the nature of pointer

  • const keyword
  1.  const int*  p 
  2.  int const *p 
  3.  int*  const p
  4.     int const a
  5.     const int a

 

 

int a = 3;
int b = 5 ;
int* const p = &a;
*p =10;
//p = &b; error:  address can not be modified , but the content can be modified
const int* p2 = &a;
p2 = &b;
//*p2 = 7; error :  address can  be modified , but the content can not be modified
int const *p3 = &a;
p3 = &b;
//*p3 = 3; error :  address can  be modified , but the content can not be modified
//*p3 = 7; error

posted @ 2015-10-06 21:56  Jonas0608  阅读(187)  评论(0编辑  收藏  举报