const int *
is a pointer to an integer constant.
That means, the integer value that it is pointing at cannot be changed using that pointer. Even though the memory where the value is stored, (foo
) was declared a normal variable and not const
, but the variable you are using to change the value if of type pointer to an integer constant.
Now, you can change the value using foo
, but not that pointer.
There is a difference between pointer to an integer constant and constant pointer to an integer.
constant pointer to an integer is defined as int * const
. You cannot make the pointer point to some other memory once you have initialized.
pointer to an integer constant is defined as int const *
or const int *
. You cannot change the value pointed to by the pointer through this pointer itself.
NOTE:
Use the standard definition of main()
int main(void) //if no command line arguments.