Where does main belong to?

dalinkwent6

Junior Member
Joined
Jun 30, 2013
Messages
114
Reaction score
16
Java was my first language and finished a c++ intro course last semester. Something that i've been wondering about is where main is?
I understand that in java it can be in any object you put it in with static methods, but where is main in c++. I've read some explanations
but i think i am missing a keypoint that allows me to see the picture. Anyone care to elaborate for me?
 
Not sure if I understand your question correctly.

The main() in c++ is similar in the sense that it can be in any .cpp file you have created.

Just like java which requires you to define the main as
static void main(String[] args) {}

C++ requires you to define the main, less strict with optional arguments, as
int main() {}


I'm primarily a java programmer, with limited C++ knowledge.
Concept-wise, they are similar with Java having less hardcore manipulation of memory.
But, with the understanding of pointers in C++ does allow you to better appreciate how Java does certain things.
 
I think you mean where main is written am i right? main is always written in a cpp source file, it's upto you whichever source file you put it into, that cpp file will be consider the main
 
If you're doing your code in just a single file without any separate files for headers and codes then the main is the last function of your code. It's at the bottom of your file but at run-time it's the first to be compiled. Any functions you write below the main will not be executed and you will get an error
 
Java was my first language and finished a c++ intro course last semester. Something that i've been wondering about is where main is?
I understand that in java it can be in any object you put it in with static methods, but where is main in c++. I've read some explanations
but i think i am missing a keypoint that allows me to see the picture. Anyone care to elaborate for me?

main(){} is essential function what you need to include in source file as in example console project. It can contain other function calls variables etc. if you done Java you know how things work around tho c++ is a f**** shotgun compared to java :)
 
Back
Top