What is the maximum no. of arguments that can be given in a command line in C?

This question is related to Oracle Interview

Showing Answers 1 - 8 of 8 Answers

varun

  • Jul 3rd, 2005
 

for a program 
int main(int argc, char **argv) .... 
^^^^ 
sizeof(int) number of arguments are possible 
hence 32767 args are possible for a 32 bit computer

  Was this answer useful?  Yes

Ashish Agrawal

  • Nov 19th, 2006
 

NEVER!If you are deciding the numbers of arguments on the basis of size of int in 32 bit compiler, it should be 2^31-1. that is almost square of 32767.And The memory allocated to argv is from RAM. SO do you really think compiler allocates memory holding 2^31-1 strings of any size!

  Was this answer useful?  Yes

karthisiva

  • Dec 21st, 2010
 

As far as I know, it depends on the first argument which represents the number of arguments.
If argc is 2 bytes in length, 65535 strings can be passed.
If argc is 4 bytes in length, 4294967295 strings can be passed.
In Both the cases first one is for program name.
And the total length should not exceed the heap size.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions