Machine-translated by Google. Questions are authored in English.
Top

Command Line Arguments Questions and Answers

Answer: D

All of the statements about the second parameter is correct. It is the collection of character pointers which of which the first represents the name of the program file.

Please log in or register to report this question.

72.

Which of the following gives the name of the program if the second parameter to the main fucntion is char **argv?

Answer: C

Correct answer: argv[0]

argv[0] holds the name by which the program was invoked, whether argv is declared as an array of pointers or as char ** - the two are equivalent as parameters.

The arguments proper begin at argv[1], which is why a program testing for arguments writes if (argc > 1). The exact contents of argv[0] are a platform convention: Unix-like systems supply the string as typed, while some others give a full path.

Please log in or register to report this question.

73.

Which character is used to separate different arguments?

Answer: C

Command line arguments are separated by space. So if you write
./output This is a single parameter
then they will interpreted as 5 command line arguments as shown : [“./output”, “This”, “is”, “single”, “parameter”].

Please log in or register to report this question.

Answer: B

Correct answer: Either single or double quotes

The shell splits the command line on whitespace, so an argument containing a space must be quoted to arrive intact. Both quoting styles achieve that.

They differ in what else they do: double quotes still allow the shell to expand variables and command substitutions inside them, while single quotes suppress everything and pass the text literally. For an argument containing only spaces either works; where the text also contains $ or a backtick, single quotes are the safer choice.

Please log in or register to report this question.

75.

Which of the following is correct to interpret Hello World as a single argument?

1. $ ./output 'Hello World'

2.  $ ./output Hello World

Answer: C

Correct answer: Only 1

The shell splits on whitespace before the program ever runs, so ./output Hello World delivers two separate arguments - argv[1] is "Hello" and argv[2] is "World", with argc of 3.

Quoting is what prevents the split: 'Hello World' reaches the program as a single argv[1], and argc is 2. Escaping the space as Hello\ World has the same effect. Only the first form therefore gives one argument.

Please log in or register to report this question.

76.

What will be the output of the following C code?

#include <stdio.h>
main()
{
    typedef int a;
    a b=2, c=8, d;
    d=(b*2)/2+8;
    printf("%d",d);
}

 

Answer: A

Correct answer: 10

The typedef is a distraction: a is simply another name for int, so b, c and d are ordinary integers.

Precedence settles the arithmetic. * and / bind tighter than + and associate left to right:

\[ (2 \times 2)/2 + 8 = 4/2 + 8 = 2 + 8 = 10 \]

The distractor 16 comes from adding before dividing. Note that c is declared and never used, which is a further piece of misdirection.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Command Line Arguments Questions and Answers || Command Line Arguments MCQ Questions and Answers || Command Line Arguments GK Questions and Answers || Command Line Arguments GK MCQ Questions || Command Line Arguments Multiple Choice Questions and Answers || Command Line Arguments GK || GK on Command Line Arguments || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming