C Programming Questions and Answers – Error Handling – 2

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Error Handling – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

advertisement

1. Which of the following causes an error?
a) Trying to read a file that doesn’t exist
b) Inability to write data in a file
c) Failure to allocate memory with the help of malloc
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

2. What is the purpose of the C function?

advertisement
advertisement
int ferror(FILE *fp)

a) They check for input errors
b) They check for output errors
c) They check for all types of errors
d) They check for error in accessing the file
View Answer

Answer: b
Explanation: None.
advertisement

3. stderr is similar to?
a) stdin
b) stdout
c) Both stdout and stdin
d) None of the mentioned
View Answer

Answer: b
Explanation: stderr is not exactly the same as stdout, but similar in the sense that both puts the output or error to the monitor.

4. What will be the output of the following C statement?

advertisement
fprintf(stderr, "error: could not open filen");

a) The diagnostic output is directly displayed in the output
b) The diagnostic output is pipelined to the output file
c) The line which caused error is compiled again
d) The program is immediately aborted
View Answer

Answer: a
Explanation: None.
advertisement

5. Which of the following function can be used to terminate the main() function from another function safely?
a) return(expr);
b) exit(expr);
c) abort();
d) both exit(expr); and abort();
View Answer

Answer: b
Explanation: None.

6. Which of the following causes an error?
a) Trying to read a file that doesn’t exist
b) Inability to write data in a file
c) Failure to allocate memory with the help of malloc
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

7. What is the purpose of the C function?

int ferror(FILE *fp)

a) They check for input errors
b) They check for output errors
c) They check for all types of errors
d) They check for error in accessing the file
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.