0

So the question is this:

const int ci = 0, &cj = ci; 

so does the const entitle every object after its created? does this read "ci is a const int" and "cj is a reference to a const int" as well? or is &cj not a const and just means "a reference to ci"?

if the const DOES encompass the entire line, what about this...

int j = i;
const int &k = i; 
int *p = &i; 

now that the const is in the middle, does it ignore the first object and create a const for everything in front of it?

Momo N
  • 119
  • 1
  • 1
  • 7
  • 2
    Hello and welcome to SO. Please take [the tour](http://stackoverflow.com/tour) and read the [help page](http://stackoverflow.com/help). Here is a nice list of [C++ books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). –  Dec 31 '16 at 00:37
  • There are too many questions in here (I count 4). Please narrow it. Refer to [ask]. – T-Heron Dec 31 '16 at 00:51
  • 1
    This seems pretty easy to test for yourself. – Lightness Races in Orbit Dec 31 '16 at 02:03

1 Answers1

3

In variable declarations, the type name and qualifiers apply to all the variables being declared in that statement. So in your first example, both ci and &cj are declared as const int.

In your second example, each declaration is a separate statement. The type names and qualifiers don't have any effect on different statements.

Barmar
  • 741,623
  • 53
  • 500
  • 612