Skip to main content

lvalue - definition

Today I found very interesting definition of lvalue in C++. According to this site:

An lvalue is an expression that refers to a memory location and allows us to take the address of that memory location via the & operator. An rvalue is an expression that is not an lvalue. 

Examples are:

  // lvalues:
  //
  int i = 42;
  i = 43; // ok, i is an lvalue
  int* p = &i; // ok, i is an lvalue
  int& foo();
  foo() = 42; // ok, foo() is an lvalue
  int* p1 = &foo(); // ok, foo() is an lvalue

  // rvalues:
  //
  int foobar();
  int j = 0;
  j = foobar(); // ok, foobar() is an rvalue
  int* p2 = &foobar(); // error, cannot take the address of an rvalue
  j = 42; // ok, 42 is an rvalue

Comments

Popular posts from this blog

Blog's new layout

As you noticed this blog has new layout from today. I hope you like it. I think new layout looks better and more modern than previous one. Please, write you opinion about new layout in comments. If you have some ideas how to make this blog better, all ideas are welcomed. Enjoy new layout and blog articles.

GDB Automatic Deadlock Detector

Have you ever had a problem with detection deadlock between threads in your C/C++ application? Would you like to do that automatically? Try this GDB Automatic Deadlock Detector from my github: GDB Automatic Deadlock Detector Picture source: http://csunplugged.org/wp-content/uploads/2015/03/deadlock.jpg1286488735

C++11 - Right angle bracket

In C++03 " >> " is always interpreted as right shift operator . It causes problem for nested template declaration like here: In above example for C++03 we have compilation error because of unintended interpretation of " >> ". Compiler interpret it as right shift operator - not like two nested vectors. Proper syntax in above situation should include space character between two " > " characters closing nested templates like here: It it not very comfortable and sometimes causes problems with finding reason of compilation error. Fortunately, C++11 standard solves that problem. It implements proper interpretation of nested templates without space between two right angle operators " > ". Therfore in C++11 following syntax: is properly interprated as two nested vectors.