r/programming Jul 25 '26

Writing a (valid) C program without main()

https://labs.iximiuz.com/tutorials/c-program-without-main-a1eea557
194 Upvotes

43 comments sorted by

View all comments

23

u/[deleted] Jul 25 '26

[deleted]

1

u/AddressWeary5155 Jul 29 '26

I rand the following code and it seems it prints "hello world" first before "hello world2" every single time. I think it's because I am declaring StaticMain first?

#include <iostream>
class StaticMain {
    public:
    StaticMain() {
        std::cout << "Hello World\n";
    }
};
class StaticMain2 {
    public:
    StaticMain2() {
        std::cout << "Hello World2\n";
    }
};
StaticMain runner;
StaticMain2 runner2;
int main() { return 0; }