C-Command Line Arguments Questions and Answers

Take Exam

Command line arguments in C allow passing values to a program at runtime through the main() function parameters argc and argv. This feature is essential for flexible and interactive program execution. Many programming questions and answers in coding interviews test this concept through practical applications and debugging scenarios. This section provides C command line argument questions with answers and explanations, helping learners strengthen their understanding of runtime input handling. These examples are useful for TCS, Tech Mahindra, and Wipro placement exams where efficiency and clarity of coding are tested.

C-Command Line Arguments

Showing 10 of 129 questions

121. Find the output void main ( ) { char s[10]; int x=256; sprintf(s, "%d",x); printf("%s",s); }

  • 0
  • 256
  • Garbage
  • NULL
Show Answer Report

122. How would you insert pre-written code into a file

  • #include <file>
  • #input<file>
  • #insert file
  • #pre
Show Answer Report

123. Program name in command line argument is

  • First argument
  • Last argument
  • Not part of command line
  • None of these
Show Answer Report

124. Argument counter in commandline argument is of type

  • int
  • char
  • float
  • void
Show Answer Report

125. In command line argument coammands are treated as

  • internal commands
  • external commands
  • Both internal and external
  • None of the above
Show Answer Report

126. What is the output if execute the command with following parameter/ C:\ compress letter.txt<u> Compress</u> main (int x,chart *p[ ] ) { printf(&quot;%d&quot;, x); }

  • 1
  • 3
  • 2
  • 0
Show Answer Report

127. Find the output if command is given command 10 20 30 40 main (int x, char *y [ ] ) { int sum=0; int r,i; for (i=0;i&lt;x;i++) { r=atoi(y[i]); sum=sum+r; } printf(&quot;%d&quot;,sum); }

  • 10
  • 100
  • 1000
  • None of above
Show Answer Report

128. Find the output main (int x, char*y[ ] , char *z[ ] ) { int i =0; while (z[i]) { printf(&quot;%s&quot;, z[i]; i++; } }

  • print list of environment variables
  • Print list of command line arguments
  • Count number of command lines
  • None of the above
Show Answer Report

129. Which of the following is true in argument vector

  • it is an array of pointers
  • it is an array of strings
  • It is an array of integers
  • None of the above
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test