

MCQOPTIONS
Saved Bookmarks
This section includes 37 Mcqs, each offering curated multiple-choice questions to sharpen your C Programming knowledge and support exam preparation. Choose a topic below to get started.
1. |
What will be the output of the following C code if following commands are used to run(considering Newfile exists)?gcc -otest test.c ./test < Newfile #include <stdio.h> int main() { char ch = 'U'; putchar(ch); } |
A. | U on the screen |
B. | Undefined behaviour |
C. | Compilation Error |
D. | U in the myfile file |
E. | None of these |
Answer» B. Undefined behaviour | |
2. |
What will be the output of the following C code if following commands are used to run(considering Newfile exists)?gcc -otest test.c ./test > Newfile #include <stdio.h> int main(int argc, char **argv) { char ch = 'U'; putchar(ch); printf(" %d n", argc); } |
A. | U in Newfile and 1 in screen |
B. | U in Newfile and 2 in screen |
C. | U 1 in Newfile |
D. | U 2 in Newfile |
E. | None of these |
Answer» D. U 2 in Newfile | |
3. |
What will be the output of the following C code?#include <stdio.h> int main() { short int n; scanf("%hd", &n); printf("%hd", n); return 0; } |
A. | Whatever user types |
B. | Compilation Error |
C. | Undefined behavior |
D. | Runtime Error |
E. | None of these |
Answer» B. Compilation Error | |
4. |
What will be the output of the following C code?#include <stdio.h> int main() { char ch1[] = "HelloInterviewMania!"; char ch2[13]; scanf(ch1, "%s", ch2); printf("%s n", ch2); return 0; } |
A. | HelloInterviewMania |
B. | Nothing |
C. | Undefined behaviour |
D. | Hello |
E. | Compilation Error |
Answer» C. Undefined behaviour | |
5. |
What will be the output of the following C code?#include <stdio.h> int main() { char *num; scanf("%s", num); return 0; } |
A. | Undefined behaviour |
B. | Nothing |
C. | Compilation Error |
D. | Runtime Error |
E. | None of these |
Answer» C. Compilation Error | |
6. |
What will be the output of the following C code?#include <stdio.h> int main() { int num; scanf("%d", num); printf("%d n", num); return 0; } |
A. | Whatever user types |
B. | Compilation Error |
C. | Depends on the standard |
D. | Undefined behavior |
E. | None of these |
Answer» E. None of these | |
7. |
What will be the output of the following C code?#include <stdio.h> int main() { short int num; scanf("%h*d", &num); printf("%hd", h); return 0; } |
A. | Undefined behavior |
B. | Compilation Error |
C. | Runtime Error |
D. | Somegarbage value |
E. | None of these |
Answer» C. Runtime Error | |
8. |
What will be the output of the following C code?#include <stdio.h> int main() { short int n; scanf("%*hd", &n); printf("%hd", n); return 0; } |
A. | Garbage value |
B. | Compilation Error |
C. | Runtime Error |
D. | Whatever user types |
E. | None of these |
Answer» B. Compilation Error | |
9. |
What will be the output of the following C code if 2 character is typed by the user?#include <stdio.h>#include <string.h> int main() { char line[25]; fgets(line, 25, stdin); printf("%d n", line[2]); return 0; } |
A. | Undefined behaviour |
B. | 25(ascii value of newline character) |
C. | Compilation Error |
D. | 64 |
E. | None of these |
Answer» E. None of these | |
10. |
What will be the output of the following C code?#include <stdio.h>#include <string.h> int main() { char line[25]; FILE *fp; fp = fopen("file.txt", "r"); while (fgets(line, 25, fp)) fputs(line, stdout); return 0; } |
A. | No.of lines present in file.txt |
B. | Infinite loop |
C. | Compilation error |
D. | Segmentation fault |
E. | None of these |
Answer» E. None of these | |
11. |
What will be the output of the following C function when EOF returns?int fputs(char *line, FILE *fp) |
A. | t character in array line is encountered |
B. | character of array line is encountered |
C. | When an error occurs |
D. | n character in array line is encountered |
E. | None of these |
Answer» D. n character in array line is encountered | |
12. |
What does the following command line signify?prog1|prog2 |
A. | It runs both the programs, pipes output of prog2 to input of prog1 |
B. | It runs prog1 first, prog2 second |
C. | It runs prog2 first, prog1 second |
D. | It runs both the programs, pipes output of prog1 to input of prog2 |
E. | None of these |
Answer» E. None of these | |
13. |
What will be the output of the following C code?#include <stdio.h> int main(int argc, char** argv) { char *str = "Interveiw"; int n = 3; printf("%10.*s", n, str); } |
A. | Int(note:6 spaces after Int) |
B. | Interveiw(note:2 spaces after myworld) |
C. | Interveiw(note:2 spaces before myworld) |
D. | Int |
E. | None of these |
Answer» B. Interveiw(note:2 spaces after myworld) | |
14. |
What will be the output of the following C code?#include <stdio.h> int main() { int n = 25, m = 13; printf("%d %d %d", n, m); } |
A. | 25 13 Garbage value |
B. | 25 13 |
C. | Undefined behaviour |
D. | 13 25 |
E. | None of these |
Answer» B. 25 13 | |
15. |
What will be the output of the following C code?#include <stdio.h> int main() { int m = 31, n = 13, p = 30; printf("%d %d ", m, n, p); } |
A. | Compilation Error |
B. | Garbage value |
C. | 31 13 30 |
D. | 13 30 |
E. | 31 13 |
Answer» F. | |
16. |
What will be the output of the following C code?#include <stdio.h> int main() { char *str = "Interview"; int n = 30; printf("%*s", n, str); } |
A. | Undefined |
B. | Interview |
C. | Interview (note:followed by two spaces after Interview) |
D. | Interview(note: spaces to the left of Interview) |
E. | None of these |
Answer» E. None of these | |
17. |
What will be the output of the following C code?#include int main() { int n = 15, m = 8; printf("%d n", printf("%d %d ", n, m)); } |
A. | 15 8 5 |
B. | 15 8 |
C. | Garbage value |
D. | Compilation Error |
E. | None of these |
Answer» B. 15 8 | |
18. |
What will be the output of the following C code?#include <stdio.h>#include <string.h> int main() { char line[]; fgets(line, 25, stdin); printf("%d n", strlen(line)); return 0; } |
A. | 25 |
B. | Any length since line did not end with null character |
C. | Compilation Error |
D. | Runtime Error |
E. | None of these |
Answer» D. Runtime Error | |
19. |
Identify N library function for line input and output in the following C code?#include <stdio.h> int N(char *str, FILE *iop); { int ch; while (ch = *str++) putc(ch, iop); return ferror(iop) ? EOF : 0; } |
A. | fputs |
B. | fgets |
C. | putc |
D. | getc |
E. | Compilation Error |
Answer» F. | |
20. |
What is the meaning of the following C statement?printf( %10s , state); |
A. | Print empty spaces if the string state is less than 10 characters |
B. | Print the last 10 characters of the string |
C. | 10 spaces before the string state is printed |
D. | All of above |
E. | None of these |
Answer» B. Print the last 10 characters of the string | |
21. |
What will be the output of the following C code?#include <stdio.h> int main() { short int num; scanf("%*d", &num); printf("%hd", num); return 0; } |
A. | Whatever user types |
B. | Runtime Error |
C. | Garbage value |
D. | Compilation Error |
E. | None of these |
Answer» D. Compilation Error | |
22. |
What will be the output of the following C code (when 10 and 20 are entered)?#include <stdio.h> void main() { int n1, n2; printf("Enter Numbers: "); scanf("%d", &n2); scanf("%d", &n1); printf("%d t%d n", n2, n1); } |
A. | 10 Garbage value |
B. | Garbage value 20 |
C. | Compilation Error |
D. | Undefined behaviour |
E. | 10 20 |
Answer» F. | |
23. |
What will be the output of the following C code?#include <stdio.h> int main() { char ch = ' '; putchar(ch); } |
A. | Nothing |
B. | Undefined behaviour |
C. | 0 |
D. | Compilation Error |
E. | None of these |
Answer» B. Undefined behaviour | |
24. |
What will be the output of the following C code if following commands are used to run and if Newfile does not exist?gcc -o test test.c ./test > Newfile #include <stdio.h> int main(int argc, char **argv) { char ch = 'N'; putchar(ch); printf(" %d n", argc); } |
A. | Depends on the standard |
B. | Depends on the system |
C. | N 2 in Newfile |
D. | N 1 in Newfile |
E. | None of these |
Answer» E. None of these | |
25. |
What is the meaning of the following C statement? |
A. | Print empty spaces if the string state is less than 10 characters |
B. | Print the last 10 characters of the string |
C. | 10 spaces before the string state is printed |
D. | All of above |
E. | None of these |
Answer» B. Print the last 10 characters of the string | |
26. |
The syntax to print a % using printf statement can be done by ________. |
A. | % |
B. | %% |
C. | % |
D. | % |
E. | None of these |
Answer» C. % | |
27. |
What will be the output of the following C code (when 10 and 20 are entered)? |
A. | 10 Garbage value |
B. | Garbage value 20 |
C. | Compilation Error |
D. | Undefined behaviour |
E. | 10 20 |
Answer» F. | |
28. |
Which of the following doesn t require an & for the input in scanf()? |
A. | float name[15]; |
B. | int name[15]; |
C. | char name[15]; |
D. | All of above |
E. | None of these |
Answer» D. All of above | |
29. |
Identify N library function for line input and output in the following C code? |
A. | fputs |
B. | fgets |
C. | putc |
D. | getc |
E. | Compilation Error |
Answer» F. | |
30. |
What will be the output of the following C function when EOF returns? |
A. | t character in array line is encountered |
B. | character of array line is encountered |
C. | When an error occurs |
D. | n character in array line is encountered |
E. | None of these |
Answer» D. n character in array line is encountered | |
31. |
What is the size of array line used in fgets(line, maxline, *fp) function? |
A. | Size is dynamic |
B. | maxline + 1 |
C. | maxline |
D. | maxline 1 |
E. | None of these |
Answer» D. maxline 1 | |
32. |
What will be the output of the following C code if 2 character is typed by the user? |
A. | Undefined behaviour |
B. | 25(ascii value of newline character) |
C. | Compilation Error |
D. | 64 |
E. | None of these |
Answer» E. None of these | |
33. |
What will be the output of the following C code if following commands are used to run and if Newfile does not exist? |
A. | Depends on the standard |
B. | Depends on the system |
C. | N 2 in Newfile |
D. | N 1 in Newfile |
E. | None of these |
Answer» E. None of these | |
34. |
What will be the output of the following C code if following commands are used to run(considering Newfile exists)? |
A. | U on the screen |
B. | Undefined behaviour |
C. | Compilation Error |
D. | U in the myfile file |
E. | None of these |
Answer» B. Undefined behaviour | |
35. |
putchar(c) function/macro always outputs character c to the __________. |
A. | standard output |
B. | depends on the standard |
C. | screen |
D. | depends on the compiler |
E. | None of these |
Answer» B. depends on the standard | |
36. |
What does the following command line signify? |
A. | It runs both the programs, pipes output of prog2 to input of prog1 |
B. | It runs prog1 first, prog2 second |
C. | It runs prog2 first, prog1 second |
D. | It runs both the programs, pipes output of prog1 to input of prog2 |
E. | None of these |
Answer» E. None of these | |
37. |
For a typical program, the input is taken using _________. |
A. | Files |
B. | Command-line |
C. | scanf |
D. | All of above |
E. | None of these |
Answer» E. None of these | |