Possible Duplicates:
main(int argc, char *argv[])
Main's Signature in C++
If i write:
int main(int argc, char** argv)
i get proper commandline input. What would happen if i wrote say,
int main(int foo, double fooDouble, fooType FooVar)
Is this OS-dependent or does it depend on the compiler?
The first parameter, argc (argument count) is an integer that indicates how many arguments were entered on the command line when the program was started. The second parameter, argv (argument vector), is an array of pointers to arrays of character objects.
Amongst other things, it allows for quick checking that the correct number of arguments has been passed. 2 ... argc shall be the number of arguments passed to the program from the environment in which the program is run. ....
argv and argc are how command line arguments are passed to main() in C and C++. argc will be the number of strings pointed to by argv . This will (in practice) be 1 plus the number of arguments, as virtually all implementations will prepend the name of the program to the array.
Given that it does compile, it will still only be called with the argc and argv arguments.
So your fooDouble will get the pointer value of argv, and FooVar will get whatever value is in that register/stack space used for that argument position (which may not have been initialized by the callee, so it may hold any undefined value).
This code doesn't even have to compile. If it does, undefined behaviour may occur.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With