Why const variable is lvalue in C++?

Viewed 384

I've started learning C++ via this page.

The concepts of rvalue and lvalue were confusing for me, especially this:

Note: const variables are considered non-modifiable l-values.

I don't understand that const variable can be lvalue. Is there any example code that the const variable is used as lvalue in practice? I see no difference between rvalue and non-modifiable lvalue.

1 Answers

Let assume you have statement like this

const int con=10;     //con is non-modifiable l-value
  • you can not modify value of con .
  • But con has address(&con).

So it is non-modifiable l-value.

code:

#include<iostream>

int main(void)
{
    const int con=10; //con is non-modifiable l-value
    std::cout<<con;
}
Related