1

Possible Duplicate:
What is the difference between const int*, const int * const, and int const *?

I am trying to understand how const works in a function parameter. What is the difference between void function(int const *&i); and void function(const int *&i);? And I would appreciate if you gave an example of their implementation and of the usage of i.

Community
  • 1
  • 1
ibrahim
  • 3,254
  • 7
  • 42
  • 56

4 Answers4

3

They are the same, just read it from right to left:

First example: i is a reference to a pointer of a constant integer.

Second example: i is a reference to a pointer of an integer constant.

The placement of const only changes things on either side of the pointer. For example:

const int* i

means: i is a pointer to a constant integer

whereas int* const i

means: i is a constant pointer to an integer.

Marlon
  • 19,924
  • 12
  • 70
  • 101
0

Those declarations are equivalent. For more info, see this page.

Brian Kelly
  • 19,067
  • 4
  • 53
  • 55
0

Best place for const correctness is the - C++ FAQ Lite

naumcho
  • 18,671
  • 14
  • 48
  • 59
0

They're both the same.

It means a reference to a pointer to a const int.

Mark B
  • 95,107
  • 10
  • 109
  • 188