Interview Questions

C/C++ Questions only (Structures, Unions, and Enumerations)

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


(Continued from previous question...)

C/C++ Questions only (Structures, Unions, and Enumerations)

1. What's the difference between struct x1 { ... }; and typedef

struct { ... } x2; ?

2. Why doesn't "struct x { ... }; x thestruct;" work?

3. Can a structure contain a pointer to itself?

4. What's the best way of implementing opaque (abstract) data types

in C?

5. I heard that structures could be assigned to variables and passed

to and from functions, but K&R1 says not.

6. Why can't you compare structures?

7. How are structure passing and returning implemented?

8. Can I pass constant values to functions which accept structure

arguments?

9. How can I read/write structures from/to data files?

10. How can I turn off structure padding?

11. Why does sizeof report a larger size than I expect for a

structure type?

12. How can I determine the byte offset of a field within a

structure?

13. How can I access structure fields by name at run time?

14 I have a program which works correctly, but dumps core after it

finishes. Why?

15. Can I initialize unions?

16. What is the difference between an enumeration and a set of

preprocessor #defines?

17. Is there an easy way to print enumeration values symbolically?

(Continued on next question...)

Other Interview Questions