I know it processing the c++ code, converts it into machine code, creating object files, and then links them into the executable
The thing I did not understand was how the final product would run if there were multiple sources
This is a contradiction...
You miss some aspects of the first point that makes you not having a proper understanding the second.
I try to summarize in brief:
- Each cpp file is a set of declaration that can be either object instances (aka "global variables") or function ("sequence of expressions and statements") each having a name.
Some of those declaration are "external" other "internal" (by default, functions are "external", tgat means "visible outside the file they are in")
- The translation the compiler does on each cpp file produces obj files where code is translated into machine code, and where external names are mapped in a symbol table.
- The linker peeks all the obj-s and libraries and resolve the mapped names with their respective references they have.
To let this process to succeed, all linked names must be unique (or mangled as such).
One of the names (corresponding to the main function)is then mapped in the exe file as the "applicaion entry point" (well, not exacly, the entry point is an internally CRT initializer that calls main at the end...) so that when the operating system loads the application the execution will start from there.
If you follow these three steps, there is no reason why your question should take place.
The program flows in the way the various functions reciprocally call each other. No matter where they originally came from.
There is no "parallelism" in a C++ classic program.
The question should still exist, however it could have been slightly more direct. I understand how having multiple functions and variables withing a single .cpp work. I know extra functions must be called, from within the main function, to be 'executed'. I, however, did not understand how things would work having multiple .cpp files all with their own "main functions" because I had never been instructed, read about, or tried this before. Cedric Moonen understood exactly what I was doing wrong, made mention of it, and my confusion of how having multiple .cpp files work. I now understand it's used for organizational purposes, and works no differently that having multiple functions within one file. Nevertheless I appreciate the attempt at helping me.
I, however, did not understand how things would work having multiple .cpp files all with their own "main functions" because ...
After I told that in all a program (no matter with how many files) names bust be unique, the question become meaningless:
What is the meaning (in mathematical sense) of the words "main functions"?
If you link more file having each one a main function, the result is a linker error.
You have never been instructed about how to do that, simply because it cannot work.
Anyway, it doesn't matter how: the important thing is that you understood what was the problem.
After long search on net i found formula.
I have find formula Permutations with repetition on net
n^r Where n=length of string and r=combination choice
I want to make combination according to this formula n^r.
According to this formila n^r=9 combination possible here like this
Here i am trying but stuck in inner loop.
for( int k=0;k<nl;k++)
//Here i am stuck please help me