C (Turbo C) — predict the output when using the Turbo C globals _argc and _argv. Command used: cmd> sample Jan Feb Mar /* sample.c */ #include<stdio.h> #include<dos.h> int main(int arc, char *arv[]) { int i; for (i = 1; i < _argc; i++) printf("%s ", _argv[i]); return 0; } What is printed?

Difficulty: Easy

Correct Answer: Jan Feb Mar

Explanation:


Introduction / Context:
This question tests knowledge of Turbo C's non-standard globals _argc and _argv and how they mirror the standard argc/argv. It also evaluates understanding of how command-line arguments are iterated and printed.


Given Data / Assumptions:

  • Invocation: sample Jan Feb Mar.
  • Loop prints _argv[i] for i = 1 to _argc - 1.
  • Each token is followed by a trailing space in the printf format.


Concept / Approach:
_argv[0] refers to the program name ("sample"). The loop begins at i = 1, so it prints only user-supplied arguments. The three arguments are "Jan", "Feb", and "Mar". The output will be those three separated by spaces (with a trailing space, which is visually harmless).


Step-by-Step Solution:

1) _argc equals 4: {"sample", "Jan", "Feb", "Mar"}.2) Loop i = 1..3 prints "Jan ", "Feb ", "Mar ".3) Combined visible output: "Jan Feb Mar".


Verification / Alternative check:
Changing the command to sample A B prints "A B". Starting at i = 0 would also print the program name, which this code intentionally avoids.


Why Other Options Are Wrong:

  • No output: The loop iterates three times.
  • sample Jan Feb Mar: The code starts from i = 1, not 0.
  • Error: The code compiles in Turbo C where _argc/_argv are available.


Common Pitfalls:
Assuming standard C only; here the code relies on Turbo C extensions but still runs as intended in that environment.


Final Answer:
Jan Feb Mar

More Questions from Command Line Arguments

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion