rvalue_lvalue#2

PHOTO EMBED

Fri Mar 11 2022 10:10:54 GMT+0000 (Coordinated Universal Time)

Saved by @gtsekas #c++

#include <iostream>

void f(char*&&) { std::cout << 1; }
void f(char*&) { std::cout << 2; }

int main() {
   char c = 'a';
   f(&c);
}
content_copyCOPY

c is an lvalue char. &c returns a pointer to the lvalue c, but that pointer itself is an rvalue, since it's just a nameless temporary returned from operator&. The first overload of f takes an rvalue reference to char *, the second takes an lvalue reference to char*. Since the pointer is an rvalue, the first overload is selected, and 1 is printed.

https://cppquiz.org/