Skip to content
Quiz · Variables and Types · lesson 9 of 10

Quiz — static inside a function

What does the program print?

C++
#include <iostream>

int add(int x) {
    static int total = 0;
    total = total + x;
    return total;
}

int main() {
    int total = add(5);
    std::cout << add(2) << ' ' << total << '\n';
}