Test Series - cpp

Test Number 102/102

Q: What is the signature of math in function using command line arguments?
A. int main(int argc, char const *argv[]);
B. int main(int argc, char const **argv);
C. int main(int argc, char **argv);
D. all of the mentioned
Solution: Any of the above signature can be used while using command line arguments in C++ programs.
Q: What does the first parameter of the main function represent?
A. Number of command line arguments
B. List of command line arguments
C. Dictionary of command line arguments
D. Stack of command line arguments
Solution: The first argument of the main() function represents the number of command line arguments that are passed.
Q: What does the second parameter of the main function represent?
A. Number of command line arguments
B. List of command line arguments
C. Dictionary of command line arguments
D. Stack of command line arguments
Solution: The second argument of the main() function represents the list of command line arguments that are passed.
Q: Which of the following is correct about the first parameter of the main function?
A. First argument is of int type
B. Stores the count of command line arguments
C. First argument is non-negative
D. All of the mentioned
Solution: All of the statements about the first parameter is correct. The first parameter is of non-negative integer type and stores the count of command line arguments.
Q: Which of the following is correct about the second parameter of the main function?
A. Second parameter is an array of character pointers
B. First string of the list is the name of the program’s output fle
C. The string in the list are separated by space in the terminal
D. All of the mentioned
Solution: All of the statements about the second parameter is correct. It is the collection of character pointers which of which the first represents the name of the program file.
Q: Which of the following gives the name of the program if the second parameter to the main fucntion is char **argv?
A. argv[3]
B. argv[1]
C. argv[0]
D. argv[2]
Solution: The first string in the list of command line arguments represents the name of the program which can be accessed by using argv[0].
Q: Which is the correct way of handling arguments with spaces?
A. Use single quotes
B. Either single or double quotes
C. Use double quotes
D. There is no way of handling arguments with space
Solution: One can use either single or double quotes to handle command line argument with spaces in-between. For example, ./output “Hello World” has 2 command line argument “./output” and “Hello World”.

You Have Score    /7