C Technical Interview Questions on Command Line Arguments

These C Technical Interview Questions On Command Line Arguments post providing basic, intermediate and Hard level examples in C Command Line Arguments. The Practice of these examples makes you good in C programming.


What is the output of Sample.c if it is executed from the command line?
cmd/> Sample Good Morning
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(“%d %s”, argc, argv[1]);
return 0;
}

  1. 3, Good
  2. 2, Good
  3. 3, Morning
  4. 2, Morning

Answer :

Ans : 3 ; argument counts program name also

What is the Output of following Code?
#include<stdio.h>
typedef struct error {int warning, err, exception;} ERROR;
int main()
{
ERROR e;
printf(“%d\n”, e.err);
return 0;
}

  1. Compile time error
  2. Garbage value
  3. 1
  4. 2

Answer :

Ans : 2 ; 

What is the Output of following Code?
#include<stdio.h>
int main()
{
typedef int Integer ;
static Integer *ptr;
float val = 90;
ptr = (int*)&val;
printf(“%d\n”, *ptr);
return 0;
}

  1. 0
  2. 90
  3. Compile time error
  4. Garbage value

Answer :

Ans : 1 ; 

What is the output of Sample.c if it is executed from the command line?
cmd> Sample friday tuesday sunday
#include<stdio.h>
int main(int argc, char *argv[])
{
printf(“%c”, **++argv);
return 0;
}

  1. c
  2. s
  3. t
  4. f

Answer :

Ans : 4 ; 

What is the output of Sample.c if it is executed from the command line?
cmd/> Sample
#include<stdio.h>
int main(int argc, char **argv)
{
printf(“%s\n”, argv[argc-1]);
return 0;
}

  1. Program name
  2. Compile time error
  3. Runtime error : No such location
  4. null string

Answer :

Ans : 1 ; 

What is the output of Sample.c if it is executed from the command line?
cmd/> Sample One Two Three
int main(int argc, char **argv)
{
printf(“%s\n”, *++argv);
return 0;
}

  1. null string
  2. Program Name
  3. One
  4. Two

Answer :

Ans : 3 ;

What is the output of Sample.c if it is executed from the command line?
cmd/> Sample
#include<stdio.h>
void fun(int);
int main(int argc)
{
printf(“%d\n”, argc);
fun(argc);
return 0;
}
void fun(int i)
{
if(i!=4)
main(++i);
}

  1. Compile time error
  2. 1,2,3,4
  3. 1,1,1,1
  4. 1,2,3

Answer :

Ans : 2 ; 

 

Share this