Trying to find out lvalues , rvalues and allocating memory for them. So with a lot of training materials there is a bit of chaos.
An rvalue is a value that should exist only within the expression in which it was created (before C ++ 11, at least). Thus, it has an address and a block of memory that it occupies. But by definition, we cannot get the rvalue address because it is a temporary object, unlike lvalue . But even before C ++ 11, we managed to get the rvalue address by returning it from the function and saving it to the link type const (well, I think, not the address, but the value).
So, more precisely, how does the rvalue distribution work? How long does a program or OS really remember that the memory location where the rvalue was created and marked as allocated, and another object cannot take its place?
As I see it, rvalues are now stored in the same way as lvalues , but we just have other rights to access them. And they have other types of exemption - for lvalues going out of scope, for rvalues you can optimize the existence within the expression or until there are no more references to it.
source share