Subject / 929 questions

Programming MCQs

Page 2 of Programming multiple-choice questions with answers. Tap an option to check yourself.

Page 2 of 47

Advertisement
Question 24 C Language

Why is writing p = realloc(p, n); considered risky?

Correct answer C. If realloc fails it returns NULL, overwriting p and leaking the original block

Open question
Advertisement
Question 32 C Language

What is the purpose of wrapping a header file in #ifndef MYHEADER_H, #define MYHEADER_H and #endif?

Correct answer B. To stop the header's contents being processed more than once in a translation unit

Open question
Question 33 C Language

What does opening a file with fopen(name, “a”) do?

Correct answer A. Opens it for writing at the end, creating the file if it does not exist

Open question
Question 35 C Language

How does fgets(buf, n, fp) behave when it reads a line?

Correct answer D. It reads at most n - 1 characters, keeps the newline if read, and adds a null terminator

Open question
Advertisement