Skip to content
Quiz · Functions · lesson 5 of 13

Quiz — a reference to a local variable

What happens if you return a reference to a local object?

C++
#include <iostream>

const int& make_counter() {
    int count = 0;
    return count;
}

int main() {
    const int& c = make_counter();
    std::cout << c;
}

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way