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 139 views
1 answer 176 views
2 answers 164 views
1 answer 104 views
1 answer 168 views
1 answer 160 views
1 answer 140 views
...