Friday 10 November 2017

Command Line Arguments Questions in C

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

6.
What is the output of this C code (run without any commandline 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
--------------------------------------------------------------------------------------------------------

7.
In Turbo C/C++ under DOS if we want that any wild card characters in the command-line arguments should be appropriately expanded, are we required to make any special provision?

A. Yes
B. No

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

8.
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 */


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

A. myprog
B. one
C. two
D. three

Answer: B
---------------------------------------------------------------------------------------------------------

9.
If the different command line arguments are supplied at different times would the output of the following program change?

#include

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

A. Yes
B. No

Answer: B
------------------------------------------------------------------------------------------------------------
Previous Page          Home      Next Page          Last Page
------------------------------------------------------------------------------------------------------------

More Imp Topics:

Data Types       
Operators
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...