Interview Questions

C/C++ Questions only (C Preprocessor)

C++ programming on UNIX, C++ Networking,C++ Algorithm Questions and Answers


(Continued from previous question...)

C/C++ Questions only (C Preprocessor)

1. I've got some cute preprocessor macros that let me write C code

that looks more like Pascal. What do y'all think?

2. How can I write a generic macro to swap two values?

3. What's the best way to write a multi-statement macro?

4. What are .h files and what should I put in them?

5. Is it acceptable for one header file to #include another?

6. Where are header (``#include'') files searched for?

7. I'm getting strange syntax errors on the very first declaration

in a file, but it looks fine.

8. Where can I get a copy of a missing header file?

9. How can I construct preprocessor #if expressions which compare

strings?

10. Does the sizeof operator work in preprocessor #if directives?

11. Can I use an #ifdef in a #define line, to define something two

different ways?

12. Is there anything like an #ifdef for typedefs?

13. How can I use a preprocessor #if expression to detect

endianness?

14. How can I preprocess some code to remove selected conditional

compilations, without preprocessing everything?

15. How can I list all of the pre#defined identifiers?

16. I have some old code that tries to construct identifiers with a

17. macro like "#define Paste(a, b) a/**/b", but it doesn't work any more.

18.

What does the message ``warning: macro replacement within a string

literal'' mean?

19. How can I use a macro argument inside a string literal in the

macro expansion?

20. I've got this tricky preprocessing I want to do and I can't

figure out a way to do it.

21. How can I write a macro which takes a variable number of

(Continued on next question...)

Other Interview Questions