Friday 10 November 2017

Command Line Arguments Questions in C

------------------------------------------------------------------------------------------------
Previous Page             Home                    Last Page
------------------------------------------------------------------------------------------------

10.
What is the output of this C code(run without any command line arguments)?

    #include
    int main(int argc, char *argv[])
    {
        while (argv != NULL)
        printf("%s\n",  *(argv++));
        return 0;
    }

A. Segmentation fault/code crash
B. Executable file name
C. Depends on the platform
D. Depends on the compiler

Answer: A
----------------------------------------------------------------------------------------------------

11.
argv[0] in command line arguments, is

A. The name by which the program was invoked
B. The name of the files which are passed to the program
C. Count of the arguments in argv[] vector
D. None of the mentioned

Answer: A
-----------------------------------------------------------------------------------------------------

12.
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

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

A. 3 Good
B. 2 Good
C. Good Morning
D. 3 Morning

Answer: A
------------------------------------------------------------------------------------------------------

13.
What will be the output of the program (sample.c) given below if it is executed from the command line?

cmd> sample "*.c"
/* sample.c */

#include

int main(int argc, int *argv)
{
    int i;
    for(i=1; i
        printf("%s", argv[i]);
    return 0;
}

A.   *.c
B.    "*.c"
C.     sample *.c
D.     List of all files and folders in the current directory

Answer: A
----------------------------------------------------------------------------------------------------
Previous Page             Home                    Last Page
----------------------------------------------------------------------------------------------------

More Imp Topics:

Pointers
Array
Preprocessor
Structures
Control Structures
Switch Case
Printf
Variables
File Handling
Strings

100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...