How to use static variable in struct with C++

1 Answer

0 votes
#include <iostream>

struct Example {
    static int x, y;
};

int Example::x;
int Example::y;

int main() {
    Example ex;
    
    Example::x = 98;
    Example::y = 7;

    std::cout << Example::x << "\n";
    std::cout << Example::y << "\n";
}




/*
run:

98
7

*/

 



answered Jan 29, 2023 by avibootz

Related questions

1 answer 236 views
1 answer 266 views
2 answers 269 views
1 answer 190 views
1 answer 245 views
1 answer 268 views
1 answer 227 views
...