TomoLink
TCS NQT GuideTCS NQT Programming Logic & CS FundamentalsCommand Line Arguments in C explained for TCS

Command Line Arguments in C explained for TCS

Learn core concepts, essential formulas, and attempt practice questions designed on the latest TCS NQT testing patterns.

Key Concepts & Formulas

  • 1argc (argument count): Integer tracking the number of arguments passed.
  • 2argv (argument vector): Array of strings containing the arguments.
  • 3argv[0] is always the name of the executable program.

TCS NQT Style Practice Questions

Practice Question 1

If a program runs as './a.out file.txt 10', what is argc?

A) 3
B) 2
C) 1
D) 4

Correct Answer: A) 3

Step-by-step Solution: Arguments are: argv[0]='./a.out', argv[1]='file.txt', argv[2]='10'. Total count = 3.

Practice Question 2

What is stored in argv[0]?

A) Program executable path/name
B) First argument text
C) Null
D) Argc value

Correct Answer: A) Program executable path/name

Step-by-step Solution: argv[0] holds the execution path or name of the compiled program.

Study Pro-Tip

Command-line arguments are always read into argv as strings. Convert them to numbers using atoi() if needed.