C Programming - Command Line Arguments - Discussion
Discussion Forum : Command Line Arguments - True / False Questions (Q.No. 3)
3.
The first argument to be supplied at command-line must always be count of total arguments.
Discussion:
18 comments Page 1 of 2.
Tripathi said:
7 years ago
Ans: argc (ARGument Count) is int and stores number of command-line arguments passed by the user including the name of the program. So if we pass a value to a program, value of argc would be 2 (one for argument and one for program name).
The value of argc should be non negative.
Argv (ARGument Vector) is array of character pointers listing all the arguments.
If argc is greater than zero, the array elements from argv[0] to argv[argc-1] will contain pointers to strings.
Argv[0] is the name of the program, After that till argv[argc-1] every element is command -line arguments.
The value of argc should be non negative.
Argv (ARGument Vector) is array of character pointers listing all the arguments.
If argc is greater than zero, the array elements from argv[0] to argv[argc-1] will contain pointers to strings.
Argv[0] is the name of the program, After that till argv[argc-1] every element is command -line arguments.
(1)
Sukanya said:
1 decade ago
Command line argument is the information followed by program's name on the command line of operating system.
Two special built in functions are present which specify the number of arguments on command line and pointer to an array of character pointers, those are argc and argv respectively.
Hence 1st argument is always program name.
Two special built in functions are present which specify the number of arguments on command line and pointer to an array of character pointers, those are argc and argv respectively.
Hence 1st argument is always program name.
Jailani said:
1 decade ago
If the program name is hello then:
int main(int argc,char *argv){
----------------
----------------
----------------
statements;
return o;
}
The output id:
cd>exc hello.c jailani sukanya tej
the value of argc is :3
and argv[0] is hello
argv[1] is jailani
and so on.
int main(int argc,char *argv){
----------------
----------------
----------------
statements;
return o;
}
The output id:
cd>exc hello.c jailani sukanya tej
the value of argc is :3
and argv[0] is hello
argv[1] is jailani
and so on.
Soundar said:
9 years ago
Ans: FALSE, read the question again carefully (must always be count of total arguments) it says we should give the count ie the total number of argument we are going to use. Argc stores only the number of argument given during the run time.
Rohan said:
1 decade ago
@Swetha yeah correctly said me too was mistaken by the language used.
The question asked is "First argument to be supplied at command-line". They are asking If we need supply any such argument. So it's clearly false.
The question asked is "First argument to be supplied at command-line". They are asking If we need supply any such argument. So it's clearly false.
Sneha said:
9 years ago
The argc parameter is the count of total command line arguments passed to the executable on execution (including the name of the executable as the first argument).
So the answer is true.
So the answer is true.
Swetha Madhuri said:
1 decade ago
Hey guys the answer is false.
Because the question asked is first argument in command line not to main().
Hope you understand. :).
Because the question asked is first argument in command line not to main().
Hope you understand. :).
Pravin Agrawal said:
1 decade ago
Answer is TRUE. Program name itself is an argument and always be the count of total arguments.I have tried it..
SHAAN said:
1 decade ago
Answer is TRUE. The first argument to be supplied at command-line must always be count of total arguments.
Rupinder said:
1 decade ago
Answer is TRUE. Program name itself is an argument and always be the count of total arguments.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers