C Programming Multiple Choice Questions - Command Line Arguments

This section focuses on the "Command Line Arguments" in C programming. These Multiple Choice Questions (MCQ) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

1. The command line arguments are handled using?

A. void()
B. main()
C. header files
D. macros

View Answer


2. argc refers to the?

A. number of arguments passed
B. a pointer array
C. Both A and B
D. None of the above

View Answer


3. argv[] is a?

A. a pointer array
B. It points to each argument passed to the program.
C. Both A and B
D. None of the above

View Answer


4. In linux, argv[0] by command-line argument can be occupied by _________

A. ./a.out
B. ./test
C. ./fun.out.out
D. All of the above

View Answer


5. What type of array is generally generated in Command-line argument?

A. Single dimension array
B. 2-Dimensional Square Array
C. Jagged Array
D. 2-Dimensional Rectangular Array

View Answer


6. What is the index of the last argument in command line arguments?

A. argc – 2
B. argc – 1
C. argc
D. argc + 1

View Answer


7. What will be output for the following code?

#include <stdio.h>
int main(int argc, char *argv[])
{
    printf(""%d
"", argc);
    return 0;
}

A. 0
B. 1
C. error
D. Depends on the compiler

View Answer


8. What will be output for the following code?

#include <stdio.h>
int main(int argc, char *argv[])
{
    printf(""%s
"", argv[argc]);
    return 0;
}

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

View Answer


9. What will be output for the following code?

#include <stdio.h>
int main(int argc, char *argv[])
{
    printf(""%s
"", argv[-1]);
    return 0;
}

A. ./a.out
B. Segmentation fault/code crash
C. -1
D. Depends on the compiler

View Answer


10. What will be output for the following code?

#include <stdio.h>
int main(int argc, char *argv[])
{
    while (*argv  !=  NULL)
        printf(""%s
"", *(argv++));
    return 0;
}

A. ./a.out
B. Segmentation fault/code crash
C. Depends on the platform
D. Depends on the compiler

View Answer






Discussion



* You must be logged in to add comment.