C and C++ Programming Questions
The C and C++ languages: syntax and semantics, the type system, the standard library and STL, templates, RAII, and idiomatic modern C++. Covers writing correct code and reasoning about the language features that distinguish these systems languages from managed ones. A primary language surface for systems, game, and embedded interviews.
In C, explain what a pointer is, how to declare and initialize pointers, and show an example of pointer dereference and pointer arithmetic. Also explain the difference between a pointer-to-const and a const-pointer, with short code examples. Frame the answer for embedded systems where pointers commonly reference memory-mapped registers and peripheral buffers.
Provide a concrete example where compiler optimizations combined with the strict aliasing rule lead to incorrect program behavior in C. Explain why the optimizer is allowed to assume strict aliasing, and show two correct ways to fix the code so it is portable and safe on modern compilers.
In C++, explain const-correctness for member functions. Write a small class representing a sensor reading cache with a const getter and a non-const update method. Show how mutable and const_cast could be used and explain why mutable is preferable to casting away const in most cases.
Describe the practical differences between stack and heap allocation in C/C++ for microcontroller firmware. Include allocation/deallocation costs, lifetime, fragmentation, stack overflow risks, and when to prefer static or compile-time allocation on systems with no MMU or very limited RAM. Give at least two concrete guidelines for embedded designs.
Hardware registers are often defined using bitfields in C for convenience. Discuss portability and correctness trade-offs of using C bitfields versus explicit masks and shifts to access register fields. Cover issues such as endianness, packing, atomicity of accesses, and how compiler behavior can differ across toolchains.
Unlock Full Question Bank
Get access to all 35 C and C++ Programming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.