What will be printed as a result of the program?
#include <iostream>
using namespace std;

static int a = 0, b = 3;

int change_a() { return ++a; }
int change_b(int x) { return b+=x; }

void func(int x)
{
	static int aa = change_a();
	static int bb = change_b(x);
}

int main()
{
	func(1); func(3); func(5); func(9);
	cout << a << " " << b;
	return 0;
}
Explanation
The change_a and change_b functions will be called only once from the func function because they initialize static variables and the initialization of static variables is performed only once.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты