Command Line Arguments


  1. What does argc and argv indicate in command-line arguments?
    (Assuming: int main(int argc, char *argv[]) )











  1. View Hint View Answer Discuss in Forum

    The name of the variable argc stands for "argument count"; argc contains the number of arguments passed to the program. The name of the variable argv stands for "argument vector". A vector is a one-dimensional array, and argv is a one-dimensional array of strings. Each string is one of the arguments that was passed to the program.

    Correct Option: C

    The name of the variable argc stands for "argument count"; argc contains the number of arguments passed to the program. The name of the variable argv stands for "argument vector". A vector is a one-dimensional array, and argv is a one-dimensional array of strings. Each string is one of the arguments that was passed to the program.

    For example, the command line

    gcc -o myprog myprog.c
    would result in the following values internal to GCC:

    argc
    4

    argv[0]
    gcc

    argv[1]
    -o

    argv[2]
    myprog

    argv[3]
    myprog.c


  1. What will be the output of the following C code (run without any command line arguments)?
     #include <stdio.h>
    int main(int argc, char *argv[])
    {
    while (argv != NULL)
    printf("%s\n", *(argv++));
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Segmentation fault/code crash



  1. What will be the output of the following C code (run without any command line arguments)?
    #include <stdio.h>
    int main(int argc, char *argv[])
    {
    while (*argv != NULL)
    printf("%s\n", *(argv++));
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Executable file name


  1. What will be the output of the following C code (run without any command line arguments)?
    #include <stdio.h>
    int main(int argc, char *argv[])
    {
    while (*argv++ != NULL)
    printf("%s\n", *argv);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Segmentation fault/code crash



  1. What will be the output of the following C code (run without any command line arguments)?
    #include <stdio.h>
    int main(int argc, char *argv[])
    {
    printf("%s\n", argv[argc]);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Segmentation fault/code crash