What is the purpose of `argv` in C?

What is the purpose of argv in C?

a) It stores command-line arguments as an array of strings
b) It counts the number of command-line arguments
c) It declares variables
d) It allocates memory

Answer:

a) It stores command-line arguments as an array of strings

Explanation:

The argv parameter in C’s main() function is an array of strings, where each string represents a command-line argument passed to the program. The first element of argv (i.e., argv[0]) typically contains the name of the program itself, while subsequent elements contain the actual arguments provided by the user. argv is used in conjunction with argc (argument count) to process and utilize command-line inputs in a program.

Understanding argv is crucial for working with command-line interfaces and writing programs that can process input dynamically based on user commands.

Reference links:

https://www.rameshfadatare.com/learn-c-programming/

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top