Comment on the output of the following C code.#include <stdio.h> #include "test.h" #include "test.h" int main() { //some code }a.TRUEb.Compile time errorc.FALSEd.Depends on the compiler
Question
Comment on the output of the following C code.#include <stdio.h> #include "test.h" #include "test.h" int main() { //some code }a.TRUEb.Compile time errorc.FALSEd.Depends on the compiler
Solution
The output of the given C code depends on the content of "test.h". If "test.h" has a header guard (also known as include guard), which is a common idiom in C and C++ to avoid double inclusion when dealing with the include directive, then the code will compile successfully.
A header guard looks like this:
#ifndef TEST_H #define TEST_H // declarations and definitions #endif
This prevents the contents of the file from being processed more than once. If "test.h" does not have a header guard, then the code will result in a compile-time error due to the double inclusion of "test.h".
So, the correct answer is (d) Depends on the compiler.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.