C Programming :: Command Line Arguments

NA
SHSTTON
7
Solv. Corr.
8
Solv. In. Corr.
15
Attempted
0 M:5 S
Avg. Time

1 / 15

Choose the correct option.

which is the correct way of declaring main() when it receives command line arguments ?


Amain (int argc, char argv[])

Bmain (argc, argv) int argc; char*argv[];

Cmain () { int argc; char*argv[]; }

DNone of the above

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
3
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

2 / 15

If the following program (Helloprog) is run from the command line as HelloProg 1 2 3. what would be the output?
#include<stdio.h>
main (int argc, char*argv[])
{ 
int i;
i = argv[1] + argv [2] + argv [3];
printf("%d", i);
}

A123

BError

C6

DNone of these

Answer: Option B

Explanation:

here argv[1] argv [2] argv [3] are string type. to perform addition  convert it to integer.i=atoi( argv[1]) atoi(argv [2]) atoi( argv [3]).

Workspace

NA
SHSTTON
2
Solv. Corr.
3
Solv. In. Corr.
5
Attempted
0 M:0 S
Avg. Time

3 / 15

The following 'C' program (dumpProg) is run from the command line as "dumpProg friday tuesday Sunday". what would be the output?
#include<stdio.h>
void main (int argc, char*argv[])
{
printf("%c", **++argv);
}

Am

Bmyprog

Cf

Dfriday

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
3
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

4 / 15

The following program (HelloProg) is run from the command line as HelloProg 1 2 3. what would be the output ?

#include
void main (int argc, char*argv[])
{
int i,j=0;
for (i=0; i < argc; i++)
j = j + atoi (argv[i]);
printf ("%d",j);
}


A123

BError

C6

D"123"

ENone of these

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
2
Solv. In. Corr.
4
Attempted
0 M:0 S
Avg. Time

5 / 15

Maximum combined length of the command line arguments including the spaces between adjacent arguments is


A128 characters

B256 characters

C67 characters

DIt may vary from one operating system to another

ENone of these

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
1
Solv. Corr.
0
Solv. In. Corr.
1
Attempted
0 M:0 S
Avg. Time

6 / 15

What is the output of the following 'C' program ?

#include
void main (int argc, char*argv[], char*env[])
{
int i;
for (i=1; i printf ("%s", env[i]);
}


AList of all environment variables

BList of all command line arguments

CError

DNULL

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
1
Solv. Corr.
1
Solv. In. Corr.
2
Attempted
0 M:0 S
Avg. Time

7 / 15

If the following program i.e "myprog" is run from the command line as "a.out" . What would be the output?

#include
void main (int argc, char*argvl))
{
int i;
for (i = 1; i < argc; i++)
print[ ("%s", argv[i]);
}


A*c

BList of all .c files in the current directory

C"*c"

DNone of these

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
1
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

8 / 15

The following 'C' program (dumpProg) is run from the command line as "dumpProg friday tuesday Sunday". what would be the output?

void main (int argc, char*argv[])
{
printf("%c", **++argv);
}


Am

Bmyprog

Cf

Dfriday

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
1
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

9 / 15

The following 'C' program (dumpProg) is run from the command line as "dumpProg friday tuesday Sunday". what would be the output?

void main (int argc, char*argv[])
{
printf("%c", *++argv[1]);
}


Ar

Bm

Cf

Dy

ENone of these

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
3
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

10 / 15

If the following program (myprog) is present in the directory
c:/bc/tuesthen what would be its output ?

main (int argc, char*argv[])
{
printf ("%s", argv[0]);
}


AMYPROG

BC:\BC\TUCS\MYPROG.exe

CError

DC:\BC\TUCS

ENone of these

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace