Sail E0 Webinar

MCQs

Total Questions : 29 | Page 3 of 3 pages
Question 21.


What will be the output of the program if it is executed like below?
cmd> sample


/* sample.c */
#include<stdio.h>
int main(int argc, char **argv)
{
printf("%s\n", argv[argc-1]);
return 0;
}
  1.    0
  2.    sample
  3.    samp
  4.    No output
 Discuss Question
Answer: Option B. -> sample


Question 22.


What will be the output of the program (sample.c) given below if it is
executed from the command line (Turbo C in DOS)?
cmd> sample 1 2 3


/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
int j;
j = argv[1] + argv[2] + argv[3];
printf("%d", j);
return 0;
}
  1.    6
  2.    sample 6
  3.    Error
  4.    Garbage value
 Discuss Question
Answer: Option C. -> Error

Here argv[1], argv[2] and argv[3] are string type. We have to convert the string to

integer type before perform arithmetic operation.

Example: j = atoi(argv[1]) + atoi(argv[2]) + atoi(argv[3]);


Question 23.


What will be the output of the program


#include<stdio.h>
void fun(int);
int main(int argc)
{
printf("%d ", argc);
fun(argc);
return 0;
}
void fun(int i)
{
if(i!=4)
main(++i);
}
  1.    1 2 3
  2.    1 2 3 4
  3.    2 3 4
  4.    1
 Discuss Question
Answer: Option B. -> 1 2 3 4


Question 24.


What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?
cmd> sample Good Morning


/* sample.c */
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("%d %s", argc, argv[1]);
return 0;
}
  1.    3 Good
  2.    2 Good
  3.    Good Morning
  4.    3 Morning
 Discuss Question
Answer: Option A. -> 3 Good


Question 25.


What will be the output of the program (myprog.c) given below if it is
executed from the command line?
cmd> myprog one two three


/* myprog.c */
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char **argv)
{
printf("%s\n", *++argv);
return 0;
}
  1.    myprog
  2.    one
  3.    two
  4.    three
 Discuss Question
Answer: Option B. -> one


Question 26.


What will be the output of the program (myprog.c) given below if it is executed
from the command line?
cmd> myprog one two three


/* myprog.c */
#include<stdio.h>
int main(int argc, char **argv)
{
printf("%c\n", **++argv);
return 0;
}
  1.    myprog one two three
  2.    myprog one
  3.    o
  4.    two
 Discuss Question
Answer: Option C. -> o


Question 27.


According to ANSI specifications which is the correct way of declaring main
when it receives command-line arguments?


A.
int main(int argc, char *argv[])
B.
int main(argc, argv)
int argc; char *argv;
C.
int main()
{
int argc; char *argv;
}
D. None of above
  1.    'c' means argument control 'v' means argument vector
  2.    'c' means argument count 'v' means argument vertex
  3.    'c' means argument count 'v' means argument vector
  4.    'c' means argument configuration 'v' means argument visibility
 Discuss Question
Answer: Option C. -> 'c' means argument count 'v' means argument vector

Answer: Option A


Question 28.

What do the 'c' and 'v' in argv stands for?


  1.    'c' means argument control 'v' means argument vector
  2.    'c' means argument count 'v' means argument vertex
  3.    'c' means argument count 'v' means argument vector
  4.    'c' means argument configuration 'v' means argument visibility
 Discuss Question
Answer: Option C. -> 'c' means argument count 'v' means argument vector


Question 29.

The maximum combined length of the command-line arguments including the spaces 

between adjacent arguments is


  1.    128 characters
  2.    256 characters
  3.    67 characters
  4.    It may vary from one operating system to another
 Discuss Question
Answer: Option D. -> It may vary from one operating system to another


Latest Videos

Latest Test Papers