Static variable of structure | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 2

Static variable of structure

I am unable to get how output of below code is 11? it should be 10 as per my logic. int foo() { return 10; } struct foobar { static int x; static int foo() { return 11; } }; int foobar::x = foo(); int main() { cout << foobar::x; return 0; } static variable of x is printed and it is having value as 10 returned by non static function foo(). why compiler prints 11 as output?

23rd Apr 2018, 3:31 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Respuestas
+ 1
hi, thank you for responding... I checked your code... I am able to understand the result... additionally, I am not making structure as static. I am still unable to understand why my posted code print 11 as output instead of 10 as output.
23rd Apr 2018, 5:23 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
помогите
23rd Apr 2018, 1:43 PM
Глеб