Whats the difference between const int const& and const int& in C++?

  • A+
Category:Languages

In c++ i can write const int const* for a constant pointer to an constant int. I can also write const int& for a const reference. So is const int const& a reference to a const int?

Thanks in advance!

 


So is const int const& a reference to a const int?

No, that's a compilation error.

Try compiling something like :

int z = 0; const int const& a= z; 

And you'll see the compiler will yell at you.

You can't duplicate const for the same type. Your premise that const int const* is a constant pointer to a constant int is wrong too.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: