Is there a limit on the number of arguments that we pass to main()
in C? As you all know, it is defined as int main(int argc, char *argv[])
.
When I call the program, I can pass arguments like so:
$ prog.exe arg1 arg2 arg3.....argn
Is there an upper bound in the number of argument that we may supply to main()
in this way?
For C++ it's at least 256 arguments.
as I know (and your first link says) the limit is 256 arguments in c++ and 127 in c. The line length is no problem since you can break a line into more lines.
The C language provides a method to pass parameters to the main() function. This is typically accomplished by specifying arguments on the operating system command line (console). There are two parameters passed to main().
Answer: Any number of arguments can be passed to a function. There is no limit on this.
According to the POSIX spec for exec
, there is a macro ARG_MAX
defined in <limits.h>
which defines the maximum number of bytes for the arguments + environment variables.
But since C doesn't define anything about that, no, there isn't an inherent cross-platform limit. You have to consult your OS manual if it doesn't define that macro.
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