Skip to content
Quiz · References and Pointers · lesson 4 of 8

Quiz — a function returning a pointer

What happens when this program runs?

C++
#include <iostream>

int* positive(int* p) {
    return *p > 0 ? p : nullptr;
}

int main() {
    int x = -7;
    std::cout << *positive(&x) << '\n';
}