Where are parameters of main() used

Pages: 12
That's what you would type in a command-line interface, ex: cmd on windows, terminal in Linux.
 
my.program  somefile.text  -f  -r

"my.program" is the name of the executable, and becomes argv[0]
"somefile.text" becomes argv[1]
"-f" becomes argv[2]
"-r" becoems argv[3]

What those parameters actually mean is entirely dependent on the program being run.
Last edited on
Definitions of main other than the standard ones work because of C linkage. The linker just sees that youve defined the symbol "main" and calls. The data passed is still the exact same though. If you define main to take two integers, its probably going to have arg count as the first integer, and part of the first argument string (interpretted as an integer) as the second integer and the pointer to the array of strings (interpreted as an integer) as the second integer.

Iirc, compilers require standard strict options enabled for whatever reason in order to catch the problem.
Last edited on
Thanxx everybody
Topic archived. No new replies allowed.
Pages: 12