MCQOPTIONS
Saved Bookmarks
This section includes 70 Mcqs, each offering curated multiple-choice questions to sharpen your Command Line Arguments knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What will be the output of the following C code (run without any command line arguments)? #include int main(int argc, char *argv[]) { printf("%s n", argv[argc]); return 0; } |
| A. | Segmentation fault/code crash |
| B. | Executable file name |
| C. | Depends on the platform |
| D. | Depends on the compiler |
| Answer» B. Executable file name | |
| 2. |
What will be the output of the following 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» B. Executable file name | |
| 3. |
What will be the output of the following C code (run without any command line arguments)? #include int main(int argc, char *argv[]) { while (argc--) printf("%s n", argv[argc]); return 0; } |
| A. | Compile time error |
| B. | Executablefilename |
| C. | Segmentation fault |
| D. | Undefined |
| Answer» C. Segmentation fault | |
| 4. |
What will be the output of the following C code (if run with no options or arguments)? #include int main(int argc, char *argv[]) { printf("%d n", argc); return 0; } |
| A. | 1 |
| B. | Depends on the platform |
| C. | Depends on the compiler |
| Answer» C. Depends on the compiler | |
| 5. |
What is the index of the last argument in command line arguments? |
| A. | argc 2 |
| B. | argc + 1 |
| C. | argc |
| D. | argc 1 |
| Answer» E. | |
| 6. |
A program that has no command line arguments will have argc _________ |
| A. | Zero |
| B. | Negative |
| C. | One |
| D. | Two |
| Answer» D. Two | |
| 7. |
What is argv[0] in command line arguments? |
| 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» B. The name of the files which are passed to the program | |
| 8. |
What is the second argument in command line arguments? |
| A. | The number of command-line arguments the program was invoked with; |
| B. | A pointer to an array of character strings that contain the arguments, one per string |
| C. | Nothing |
| D. | None of the mentioned |
| Answer» C. Nothing | |
| 9. |
What is the first argument in command line arguments? |
| A. | The number of command-line arguments the program was invoked with; |
| B. | A pointer to an array of character strings that contain the arguments |
| C. | Nothing |
| D. | None of the mentioned |
| Answer» B. A pointer to an array of character strings that contain the arguments | |
| 10. |
What will be the output of the following C statement? (assuming the input is cool brother in city ) printf( %s n , argv[argc]); |
| A. | (null) |
| B. | City |
| C. | In |
| D. | Segmentation Fault |
| Answer» B. City | |
| 11. |
Comment on the following. const int *ptr; |
| A. | You cannot change the value pointed by ptr |
| B. | You cannot change the pointer ptr itself |
| C. | You May or maynot change the value pointed by ptr |
| D. | You can change the pointer as well as the value pointed by it |
| Answer» B. You cannot change the pointer ptr itself | |
| 12. |
What is the output of this C code? #include int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; printf("%d,%d/n", *ptr, a); } |
| A. | 10,10 |
| B. | 10,11 |
| C. | 11,10 |
| D. | 11,11 |
| Answer» E. | |
| 13. |
What is the output of this C code? #include int *f(); int main() { int *p = f(); printf("%d n", *p); } int *f() { int j = 10; return &j; } |
| A. | 10 |
| B. | Compile time error |
| C. | Segmentation fault/runtime crash |
| D. | Undefined behaviour |
| Answer» B. Compile time error | |
| 14. |
Comment on the following pointer declaration? int *ptr, p; |
| A. | ptr is a pointer to integer, p is not |
| B. | ptr and p, both are pointers to integer |
| C. | ptr is a pointer to integer, p may or may not be |
| D. | ptr and p both are not pointers to integer |
| Answer» B. ptr and p, both are pointers to integer | |
| 15. |
What is the output of this C code? #include int main() { int i = 10; void *p = &i; printf("%f n", *(float*)p); return 0; } |
| A. | Compile time error |
| B. | Undefined behaviour |
| C. | 10 |
| D. | 0.000000 |
| Answer» E. | |
| 16. |
What is the output of this C code? #include int *f(); int main() { int *p = f(); printf("%d n", *p); } int *f() { int *j = (int*)malloc(sizeof(int)); *j = 10; return j; } |
| A. | 10 |
| B. | Compile time error |
| C. | Segmentation fault/runtime crash since pointer to local variable is returned |
| D. | Undefined behaviour |
| Answer» B. Compile time error | |
| 17. |
What is the output of this C code? #include int main() { char *p = NULL; char *q = 0; if (p) printf(" p "); else printf("nullp"); if (q) printf("q n"); else printf(" nullq n"); } |
| A. | nullp nullq |
| B. | Depends on the compiler |
| C. | x nullq where x can be p or nullp depending on the value of NULL |
| D. | p q |
| Answer» B. Depends on the compiler | |
| 18. |
What is the output of this C code? #include int main() { int i = 10; void *p = &i; printf("%d n", (int)*p); return 0; } |
| A. | Compile time error |
| B. | Segmentation fault/runtime crash |
| C. | 10 |
| D. | Undefined behaviour |
| Answer» B. Segmentation fault/runtime crash | |
| 19. |
What will be the output of the following 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» B. Executable file name | |
| 20. |
What will be the output of the following 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» C. Depends on the platform | |
| 21. |
What is the output of this C code? #include void foo(float *); int main() { int i = 10, *p = &i; foo(&i); } void foo(float *p) { printf("%f n", *p); } |
| A. | 10.000000 |
| B. | 0.000000 |
| C. | Compile time error |
| D. | Undefined behaviour |
| Answer» C. Compile time error | |
| 22. |
What is the output of this C code? #include void foo(int*); int main() { int i = 10; foo((&i)++); } void foo(int *p) { printf("%d n", *p); } |
| A. | 10 |
| B. | Some garbage value |
| C. | Compile time error |
| D. | Segmentation fault/code crash |
| Answer» D. Segmentation fault/code crash | |
| 23. |
What is the output of this C code? #include void main() { int x = 0; int *ptr = &x; printf("%d n", *ptr); } |
| A. | Address of x |
| B. | Junk value |
| C. | Run time error |
| Answer» A. Address of x | |
| 24. |
What is the output of this C code? #include void main() { int x = 0; int *ptr = &5; printf("%p n", ptr); } |
| A. | 5 |
| B. | Address of 5 |
| C. | Nothing |
| D. | Compile time error |
| Answer» E. | |
| 25. |
What is the output of this C code? #include void main() { int x = 0; int *ptr = &x; printf("%p n", ptr); ptr++; printf("%p n ", ptr); } |
| A. | 0xbfd605e8 0xbfd605ec |
| B. | 0xbfd605e8 0cbfd60520 |
| C. | 0xbfd605e8 0xbfd605e9 |
| D. | Run time error |
| Answer» B. 0xbfd605e8 0cbfd60520 | |
| 26. |
What is the output of this C code? #include int x = 0; void main() { int *const ptr = &x; printf("%p n", ptr); ptr++; printf("%p n ", ptr); } |
| A. | 0 1 |
| B. | Compile time error |
| C. | 0xbfd605e8 0xbfd605ec |
| D. | 0xbfd605e8 0xbfd605e8 |
| Answer» C. 0xbfd605e8 0xbfd605ec | |
| 27. |
What is the output of this C code? #include int x = 0; void main() { int *ptr = &x; printf("%p n", ptr); x++; printf("%p n ", ptr); } |
| A. | Same address |
| B. | Different address |
| C. | Compile time error |
| D. | Varies |
| Answer» B. Different address | |
| 28. |
Which is an indirection operator among the following? |
| A. | & |
| B. | * |
| C. | -> |
| D. | . |
| Answer» C. -> | |
| 29. |
Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0; |
| A. | int *ptr = &a; |
| B. | int *ptr = &a &a; |
| C. | int *ptr = a a; |
| D. | All of the mentioned |
| Answer» B. int *ptr = &a &a; | |
| 30. |
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. | |
| B. | B. |
| C. | C. |
| D. | D. |
| Answer» B. B. | |
| 31. |
What will be the output of the program (sample.c) given below if it is executed from the command line (Turbo C in DOS)? cmd> sample 1 2 3 /* sample.c */ #include int main(int argc, char *argv[]) { int j; j = argv[1] + argv[2] + argv[3]; printf("%d", j); return 0; } |
| A. | 6 |
| B. | sample 6 |
| C. | Error |
| D. | Garbage value |
| Answer» D. Garbage value | |
| 32. |
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 */ #include int main(int argc, char **argv) { printf("%c n", **++argv); return 0; } |
| A. | myprog one two three |
| B. | myprog one |
| C. | o |
| D. | two |
| Answer» D. two | |
| 33. |
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 */ #include #include int main(int argc, char **argv) { printf("%s n", *++argv); return 0; } |
| A. | myprog |
| B. | one |
| C. | two |
| D. | three |
| Answer» C. two | |
| 34. |
What do the 'c' and 'v' in argv stands for? |
| A. | 'c' means argument control 'v' means argument vector |
| B. | 'c' means argument count 'v' means argument vertex |
| C. | 'c' means argument count 'v' means argument vector |
| D. | 'c' means argument configuration 'v' means argument visibility |
| Answer» D. 'c' means argument configuration 'v' means argument visibility | |
| 35. |
To use command line arguments in C++, how many parameters are passed to the main function? |
| A. | 1 |
| B. | 2 |
| C. | 3 |
| D. | 4 |
| Answer» C. 3 | |
| 36. |
What are command line arguments? |
| A. | Arguments passed to main() function |
| B. | Arguments passed to any function |
| C. | Arguments passed to class functions |
| D. | Arguments passed to structure functions |
| Answer» B. Arguments passed to any function | |
| 37. |
What will be the output of this program? #include #include int main(int argc,char* argv[]) { int answer; answer=atoi(argv[1])+atoi(argv[2]); printf("%d",answer); return 0; } |
| A. | 50 |
| B. | 60 |
| C. | 30 |
| Answer» E. | |
| 38. |
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 |
| Answer» D. 2-Dimensional Rectangular Array | |
| 39. |
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 mentioned |
| Answer» E. | |
| 40. |
What does argc and argv indicate in command-line arguments? |
| A. | argument count, argument variable |
| B. | argument count, argument vector |
| C. | argument control, argument variable |
| D. | argument control, argument vector |
| Answer» C. argument control, argument variable | |
| 41. |
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 n", argv[argc]); return 0; } |
| A. | Yes |
| B. | No |
| Answer» C. | |
| 42. |
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 */ #include #include int main(int argc, char **argv) { int i; for(i=1; i<=3; i++) printf("%u n", &argv[i]); return 0; } If the first value printed by the above program is 65517, what will be the rest of output? |
| A. | 65525 65531 |
| B. | 65519 65521 |
| C. | 65517 65517 |
| D. | 65521 65525 |
| Answer» C. 65517 65517 | |
| 43. |
Which of the following is TRUE about argv? |
| A. | It is an array of character pointers |
| B. | It is a pointer to an array of character pointers |
| C. | It is an array of strings |
| D. | None of above |
| Answer» B. It is a pointer to an array of character pointers | |
| 44. |
What will be the output of the program (sample.c) given below if it is executed from the command line? cmd> sample friday tuesday sunday /* sample.c */ #include int main(int argc, char *argv[]) { printf("%c", *++argv[2] ); return 0; } |
| A. | s |
| B. | f |
| C. | u |
| D. | r |
| Answer» D. r | |
| 45. |
What will be the output of the program (sample.c) given below if it is executed from the command line? cmd> sample one two three /* sample.c */ #include int main(int argc, char *argv[]) { int i=0; i+=strlen(argv[1]); while(i>0) { printf("%c", argv[1][--i]); } return 0; } |
| A. | three two one |
| B. | owt |
| C. | eno |
| D. | eerht |
| Answer» D. eerht | |
| 46. |
What will be the output of the program (sample.c) given below if it is executed from the command line? cmd> sample friday tuesday sunday /* sample.c */ #include int main(int sizeofargv, char *argv[]) { while(sizeofargv) printf("%s", argv[--sizeofargv]); return 0; } |
| A. | sample friday tuesday sunday |
| B. | sample friday tuesday |
| C. | sunday tuesday friday sample |
| D. | sunday tuesday friday |
| Answer» D. sunday tuesday friday | |
| 47. |
What will be the output of the program (myprog.c) given below if it is executed from the command line? cmd> myprog friday tuesday sunday /* myprog.c */ #include int main(int argc, char *argv[]) { printf("%c", *++argv[1]); return 0; } |
| A. | r |
| B. | f |
| C. | m |
| D. | y |
| Answer» B. f | |
| 48. |
What will be the output of the program (sample.c) given below if it is executed from the command line? cmd> sample friday tuesday sunday /* sample.c */ #include int main(int argc, char *argv[]) { printf("%c", **++argv); return 0; } |
| A. | s |
| B. | f |
| C. | sample |
| D. | friday |
| Answer» C. sample | |
| 49. |
What will be the output of the program #include void fun(int); int main(int argc) { printf("%d ", argc); fun(argc); return 0; } void fun(int i) { if(i!=4) main(++i); } |
| A. | 1 2 3 |
| B. | 1 2 3 4 |
| C. | 2 3 4 |
| D. | 1 |
| Answer» C. 2 3 4 | |
| 50. |
What will be the output of the program (sample.c) given below if it is executed from the command line? cmd> sample 1 2 3 cmd> sample 2 2 3 cmd> sample 3 2 3 /* sample.c */ #include int main(int argc, char *argv[]) { printf("%s n", argv[0]); return 0; } |
| A. | sample 3 2 3 |
| B. | sample 1 2 3 |
| C. | sample |
| D. | Error |
| Answer» D. Error | |