Q:

static variables in C structs

When I try to declare a struct with a static variable in it, the code doesn't get compiled and produces the error mentioned below
#include <stdio.h>

int main (){

struct test {
    int value;
    static int staticValue = 0;
}; 

return 0;
}

The error I get is;
 expected specifier-qualifier-list before ‘static’
  static int staticValue = 0;
  ^

Can anyone tell me what am I missing here?

A:

You might not want to declare your struct inside the main function -- that limits its scope to that of the function, which is seldom what you want.
Then, in C, static refers to object lifetime, and not to struct members. What you want is a static class member, which is a C++ (and not a C) construct.

