yes...may be..i mean this
struct Sample
{
public:
Sample() {
printf("Hello World");
}
};
Sample S;
void main(void)
{
}
This is still C++ not C, I get these errors
c:\myprojects\consoletester\consoletester.c(3) : error C2061: syntax error : identifier 'public'
c:\myprojects\consoletester\consoletester.c(7) : error C2059: syntax error : '}'
c:\myprojects\consoletester\consoletester.c(10) : error C2061: syntax error : identifier 'S'
c:\myprojects\consoletester\consoletester.c(10) : error C2059: syntax error : ';'
The answer is that in C it is not possible, the only thing you can do in C or C++ without putting code in main is declare variables. In C++ you can declare a class which will envoke it's constructor (and in fact could envoke the whole program) but in C there is no way that declaring a variable envokes any user code.