Main(int x).............explaination on arguments passed thr' main

Showing Answers 1 - 3 of 3 Answers

naresh garg

  • Mar 17th, 2006
 

The main function can have the command linre arguments like in this syntax main(int x)......

the main function can have two arguments

1.  int x : tell the number of arguments in the main function that are given on the command line

2. char  *array[] :it is an array of pointers to the string and specify the file names thay you want to pass on the command line. 

  Was this answer useful?  Yes

I think u r correct but partially as there r

three arguments not 2 third one is environment

and passed as (char *env) it gives the environment details in the program

it'l help when we want to get the environment variables in our program.

  Was this answer useful?  Yes

shibaji paul

  • Apr 20th, 2006
 

I am afraid, nitil goel is also partially correct. The environment parameter is not a character pointer, rather it is a array of character pointers.The actual prototype of the main function wouold be as follows: int main (int argc, char *argv[], char * envp[])argc holds the count of the total numbers of arguments passed to the main function from the command prompt.each elements of the array argv[] holds the base address to each parameter passed from the command prompt.each elements of the array envp[] holds the base address to the environment values passed to the program by the system.Further more , in C and C++ the name of the .exe file with the absolute path is passed as the first parameters, thus the count of parameters that is argc will be one more than the actual parameters passed to the program, which is not the case for JAVA program.

  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