C Arrays Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of command line arguments in C, including argc, argv, program arguments, argument indexing, and string handling.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. argc and argv
The main() function can receive command line arguments through the argc and argv parameters.
A. The number of command line arguments
argc contains the count of command line arguments, including the program name.
A. An array containing command line argument strings
argv is an array of pointers to strings representing the command line arguments.
B. The program name or invocation name
argv[0] conventionally points to the program name or the name used to invoke the program.
C. 2
The arguments are typically argv[0] = ./program and argv[1] = hello, so argc is 2.
A. int main(int argc, char *argv[])
A common standard form is int main(int argc, char *argv[]), where argc counts arguments and argv points to their strings.
B. 4
argc includes the program name, so there are four arguments: ./program, one, two, and three.
B. argv[1]
argv[0] is conventionally the program name, so the first user-provided argument is stored at argv[1].
B. A character string
Each argv element points to a null-terminated character sequence representing an argument.
A. Using atoi()
The atoi() function from the standard library can convert a numeric string to an int, although functions such as strtol() provide better error handling.
B. 1
The program name is conventionally included in argc, so a normal invocation without additional arguments has argc equal to 1.
B. <stdlib.h>
The atoi() function is declared in the standard library header <stdlib.h>.
A. for (int i = 1; i < argc; i++)
Starting at index 1 skips argv[0], and using i < argc ensures only valid argument indexes are accessed.
C. A null pointer
The argv array is required to have a null pointer after the last argument pointer, at argv[argc].
A. Command line arguments are initially received as strings
Command line arguments are passed to the program as strings. If numeric values are required, they must be converted to an appropriate numeric type.