How to solve Command Line Arguments Coding Questions

TCS Command Line Programs

Tcs has been using TCS Command Line Programs to conduct the first round of Placements in Coding Section, TCS Command Line Arguments Programs, TCS C Compiler, Command Line Arguments Questions for TCS.

TCS Command Line Arguments Programs

This article is for TCS based command line Argument based Questions, you will get to know how to understand the the basic program and write it, Command Base Argument Coding for TCS, Command Line Arguments Questions for TCS.

Paid Material

Free Material


  • Number of Questions – 1
  • Total time to Solve – 20 mins
  • Difficulty Level – 1 Easy Questions
  • Cut-off – Solve 1 question completely or partial output.
Imp: You can check out our YouTube Tutorial for Command Line Programming at the end of the page.

IMP Note – Before going through these questions scroll below and learn command line programming else this will not be useful or click here for command Line Theory

Command Line Arguments Questions for TCS Basics

  • Keywords like getc, scanf, getch, getchar etc can not be used.
  • Instead we use command line arguments to fetch the values.

Before reading further, I will suggest not to freak out if you don’t understand TCS Command Line Arguments Programs in first go. Read everything once and then when you read again things will start to make sense. It is the best resource on the internet to know about TCS command line Argument Type Questions in TCS C Compiler.

TCS Command Line Arguments Programs

Command Line Arguments Questions for TCS

For TCS Command Line Arguments Programs let us consider this, if you wanted to write a basic C program then you would’ve written a main function that would’ve looked like – 

int main(){
// some code in Command Line Arguments Questions for TCS C Compiler

However in command line arguments we write like this – 

int main(int argc, char *argv[]){

  1. argc – It is know as Argument Count and as clear from the name it stores the Count of number of Arguments.
  2. argv[] – Pointer, contains location of all the values(arguments).
  3. *argv[] – Array of values of all the arguments.
  4. They are parameters/arguments supplied to the program when it is invoked.

Thus, now we have two things for TCS C Compiler

  1. Total Count of number of Arguments.
  2. All the values/pointer location of arguments stored in an array.

Now, you will need one more thing i.e. atoi();

  • atoi(); – Converts string into int and atoi(argv[i]); will give the value of argument at ith location in int type format.

Now you can use an int val = atoi(argv[i]); to store the value and then print it with printf(); function.

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.

int main(int argc, char *argv[]) { /* ... */ }


int main(int argc, char **argv[]) { /* ... */ }

Quick Facts for TCS Command Line Arguments Programs

argv[0] contains the default value, not the input value so –

  • All for loops must start from i = 1.
  • You must use the following condition
if(argc == 1){
// do nothing since, there are no arguments, maybe ask for arguments?
// code to apply logic and print values.
  • provided+1 +1 for file.exe
  • argv[argc] is a NULL pointer.
  • argv[0] holds the name of the program.
  • argv[1] points to the first command line argument and argv[n] points last argument.
TCS Command Line Arguments ProgramsNo of Times asked in Command Line CodingDifficulty LevelImportance
Command Line Program for Binary to Decimal25HighHigh
TCS Command Line Argument for Factorial of a Number21MediumMedium
TCS Command Line Programs Armstrong Number18MediumMedium
To check if Prime number or not27LowMedium
Sum of Digits of a Number41MediumVery High

Command Line Arguments Questions for TCS Rules for Coding Section Steps:
There is only one question for 20 minutes.

  1. It has 10 attempts(We can compile only 10 times).
  2. We must start our code from the scratch.
  3. The coding platform is divided into two, one for writing the code and other for output. We should write the whole program.
  4. We can’t use any input functions like scanf(), getch(), getchar().
  5. The input to be provided should be read as command line arguments.
Command Line Arguments Questions for TCSFrequency of Repetition in TCS QuestionsImportanceDifficulty
String Reversal Using Command Line Programming14LowVery High
Average of two Numbers for TCS39MediumMedium
Finding LCM of two Numbers51HighMedium
Finding HCF/GCD Question with CLP66HighMedium

We must only print exact output in Command Line Arguments Questions for TCS Procedure –

  1. Output must not be re-framed by extra words.
  2. If there is any error, the error will be shown in the output dialog box.
  3. The errors are clearly mentioned.
  4. If there are no errors, a message like “compiled successfully” will be printed.
  5. Along with that they will mention four test cases are ‘passed’ or maybe ‘failed’.
  6. They are indicated like private and public test cases. They have not mentioned what is the test case, which is difficult to understand in TCS Command Line Arguments Programs.

Dont Compile again and again since compiler takes 25 seconds and each time you compile 25 seconds will become lesser in the time you have to code.

Youtube Video Tutorial for Command Line Arguments Questions for TCS – 


Ques. How much time is sufficient for the preparation of this section?

Ans. We will suggest at least 2 – 3 days should be sufficient to practice for this section for TCS exam.

command line arguments questions for tcs

Most Asked Programs

You can scroll up to go to individual links of other asked programs but we first want you to learn command line programming above in the theory section and then come here to check most asked programs and then finally go to individual links to find other asked programs for command line.

Beware – Most websites are copying PrepInsta’s content/codes etc. Only trust us. If you see our copied content anywhere please contact us on Facebook and help us :).

Greatest Number Code

#include <stdio.h>

int main(int argc, char *argv[])


            int c[10];

            int i,temp,j,greatest;

            j = 0;

            for(i=1; i<argc; i++)


            temp = atoi(argv[i]);

            c[j] = temp;



            greatest = c[0];

            for (i = 0; i < 10; i++) {

            if (c[i] > greatest) {

            greatest = c[i];



            printf("Greatest of ten numbers is %d", greatest);

            return 0;


Fibonacci Series

#include <stdio.h>

int main(int argc, char *argv[])


             int n, first = 0, second = 1, next, c;

            n = atol(argv[1]);

            printf("First %d terms of Fibonacci series are :-\n",n);

            for ( c = 0 ; c < n ; c++ )


             if ( c <= 1 )

               next = c;



             next = first + second;

             first = second;

               second = next;




   return 0;


Factorial Code


int main(int argc, char *argv[])


              int n,i;

            unsigned long long factorial = 1;

              n = atol(argv[1]);

              for(i=1; i<=n; ++i)


            factorial *= i;


            printf("Factorial of %d = %llu", n, factorial);


Code for String Reversal

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int main(int argc, char *argv[])


            int k;

               char temp;

              int i,j=0;

              int strsize = 0;

               for (i=1; i<argc; i++) {

       strsize += strlen(argv[i]);

        if (argc > i+1)



   char *cmdstring;

   cmdstring = malloc(strsize);

   cmdstring[0] = '\0';

   for (k=1; k<argc; k++) {

        strcat(cmdstring, argv[k]);

        if (argc > k+1)

            strcat(cmdstring, " ");


   i = 0;

   j = strlen(cmdstring) - 1;

   while (i < j) {

      temp = cmdstring[i];

      cmdstring[i] = cmdstring[j];

      cmdstring[j] = temp;




   printf("\nReverse string is :%s", cmdstring);



Swapping Numbers

#include <stdio.h>

int main(int argc, char *argv[])


            double firstNumber, secondNumber, temporaryVariable;

              firstNumber = atol(argv[1]);

              secondNumber = atol(argv[2]);

              temporaryVariable = firstNumber;

              firstNumber = secondNumber;

            secondNumber = temporaryVariable;

              printf("\nAfter swapping, firstNumber = %.2lf\n", firstNumber);

            printf("After swapping, secondNumber = %.2lf", secondNumber);

   return 0;

Review Date
Reviewed Item
TCS Command Line Programs
Author Rating

Please Login/Signup to comment

3 comments on “How to solve Command Line Arguments Coding Questions”

  • bhavana

    Loved this site.. Very helpful information. I have searched for this topic in different websites but didnt found this much data.
    Great job PREPINSTA .. keep on doing