Thursday, May 07, 2009

[C Programming] Difference between const int* and int* const

const int* - a variable pointer pointing to a constant integer.
int* const - a constant pointer pointing to a variable integer.

E.g.
int i = 7;
const int* p = &i;

*p = 8; //ERROR!


* The trick is to read from right to left. :)

2 comments:

  1. Refreshes me of C++ programming, =)

    ReplyDelete
  2. Hehe, took Unix programming this Sem. Learnt about C programming also. :)

    ReplyDelete