+ 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?
3 Answers
+ 3
There is no static struct in C++
https://stackoverflow.com/questions/14976971/static-struct-with-static-members?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Here's your code (more specific)
https://code.sololearn.com/c8kAA5HB93HB/?ref=app
+ 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.
0
ĐżĐŸĐŒĐŸĐłĐžŃĐ”