Explore topic-wise MCQs in C Programming.

This section includes 12 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 happens when we use the following C statement?
fprintf(stderr, "error: could not open file");

A. The diagnostic output is pipelined to the output file
B. The program is immediately aborted
C. The diagnostic output is directly displayed in the output
D. The line which caused error is compiled again
E. None of these
Answer» D. The line which caused error is compiled again
2.

What will be the output of the following C code?
 #include <stdio.h>
int main()
{
char buff[25];
stderr = stdin;
fscanf(stderr, "%s", buff);
printf("%s n", buff);
}

A. Whatever user types
B. Compilation error
C. Undefined behaviour
D. Nothing
E. None of these
Answer» B. Compilation error
3.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp = stdout;
stderr = fp;
fprintf(stderr, "%s", "Interveiw Mania");
}

A. Undefined behaviour
B. Garbage value
C. Interveiw Mania
D. Compilation Error
E. None of these
Answer» D. Compilation Error
4.

What will be the output of the following C code?
#include <stdio.h>
int main()
{
FILE *fp;
char ch;
int num = 0;
fp = fopen("file1.txt", "r");
while (!feof(fp))
{
ch = getc(fp);
putc(ch, stdout);
}
}

A. Prints to the screen content of file1.txt completely
B. Prints to the screen some contents of newfile1.txt
C. Compilation error
D. Segmentation fault
E. None of these
Answer» E. None of these
5.

What is the purpose of the C function?
int ferror(FILE *fp)

A. They check for error in accessing the file
B. They check for all types of errors
C. They check for input errors
D. They check for output errors
E. None of these
Answer» E. None of these
6.

What is the output of the following C code if there is no error in stream fp?
#include <stdio.h>
int main()
{
FILE *fp;
fp = fopen("file1", "w");
printf("%d n", ferror(fp));
return 0;
}

A. 1
B. Compilation Error
C. 0
D. Garbage value
E. Any nonzero value
Answer» D. Garbage value
7.

What will be the output of the following C statement?
fprintf(stderr, "error: could not open filen");

A. The diagnostic output is pipelined to the output file
B. The program is immediately aborted
C. The diagnostic output is directly displayed in the output
D. The line which caused error is compiled again
E. None of these
Answer» D. The line which caused error is compiled again
8.

What will be the output of the following C statement?

A. The diagnostic output is pipelined to the output file
B. The program is immediately aborted
C. The diagnostic output is directly displayed in the output
D. The line which caused error is compiled again
E. None of these
Answer» D. The line which caused error is compiled again
9.

What is the purpose of the C function?

A. They check for output errors
B. They check for all types of errors
C. They check for error in accessing the file
D. They check for input errors
E. None of these
Answer» B. They check for all types of errors
10.

What happens when we use the following C statement?

A. The diagnostic output is pipelined to the output file
B. The program is immediately aborted
C. The diagnostic output is directly displayed in the output
D. The line which caused error is compiled again
E. None of these
Answer» D. The line which caused error is compiled again
11.

Which of the following function can be used to terminate the main function from another function safely?

A. exit(expr);
B. abort();
C. both exit(expr); and abort();
D. return(expr);
E. None of these
Answer» B. abort();
12.

What is the output of the following C code if there is no error in stream fp?

A. 1
B. Compilation Error
C. 0
D. Garbage value
E. Any nonzero value
Answer» D. Garbage value