1

What is the difference between following two statements?

const std::vector<int> v1; 

and

std::vector<int> const v2;

Is both statements equivalent?

msc
  • 33,420
  • 29
  • 119
  • 214
  • 1
    Yes. They are both equal. The best way to understand `const` is to read it as applying to the token left to it (Unless it's the leftmost token - in that case it applies to the immediate token to the right). – nakiya Jun 01 '17 at 07:03
  • 1
    https://isocpp.org/wiki/faq/const-correctness#overview-const – nakiya Jun 01 '17 at 07:04
  • 2
    @nakiya: Please put answers in the answers section. – Bathsheba Jun 01 '17 at 07:07

1 Answers1

2

Yes. They are both equal. The best way to understand const is to read it as applying to the token left to it (Unless it's the leftmost token - in that case it applies to the immediate token to the right).

See https://isocpp.org/wiki/faq/const-correctness#overview-const

Bathsheba
  • 231,907
  • 34
  • 361
  • 483