What are command-line arguments in C used for?

What are command-line arguments in C used for?

a) Passing input values to a program during execution
b) Declaring variables
c) Allocating memory
d) Defining macros

Answer:

a) Passing input values to a program during execution

Explanation:

Command-line arguments in C allow users to pass input values to a program when it is executed. These arguments are passed to the main() function via argc (argument count) and argv (argument vector), where argc indicates the number of arguments, and argv is an array of strings representing the arguments. Command-line arguments are useful for making programs more flexible and allowing them to process different inputs without changing the source code.

Understanding how to use command-line arguments is essential for writing versatile programs that can handle a variety of tasks based on user input.

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