How does argc
function in C?
a) It counts the number of command-line arguments passed
b) It stores command-line arguments as strings
c) It declares global variables
d) It allocates memory dynamically
Answer:
a) It counts the number of command-line arguments passed
Explanation:
argc
(argument count) is an integer parameter in C’s main()
function that indicates the number of command-line arguments passed to the program. It includes the program’s name as the first argument, so argc
is always at least 1. argc
is used alongside argv
(argument vector) to control the flow of a program based on the number of inputs provided by the user.
Understanding argc
is essential for managing command-line input effectively, allowing for dynamic program behavior based on user input.