void tick(void) { static int c = 0; c++; printf("%d ", c); } is called three times from main. What is printed?
Correct answer
A. 1 2 3
13 views
A. 1 2 3
13 views
Static storage duration gives the local object a single instance for the whole program, initialised once before main starts, so each call increments the remembered value. An automatic local would restart at zero and print 1 1 1. Static locals are zero-initialised by default when no initialiser appears, unlike automatic variables whose value is indeterminate.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.