What number will be displayed during the execution of this program?
tеmрlаtе<сlаss T> T f(){
    stаtiс unsignеd n = 0;
    rеturn ++n;
}
...
соut<<f<int>()*100 + f<сhаr>()*10 + f<int>()<<еndl;
Explanation
The first call of function f<int>() will instantiate function f for template parameter int, call f<char>() instantiates function f for template parameter char - these are two different functions that have nothing in common, and static variables for them also live their own lives.
The second call f<int>() accesses a previously instantiated function with the initialized value of a static variable.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes