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
  • 32,079
  • 22
  • 110
  • 197
  • 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
  • 227,678
  • 33
  • 352
  • 470