← All CPP Flashcard Decks

CPP Interoperability & System Programming Flashcards

6 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 6 CPP Interoperability & System Programming flashcards as text
  1. What is the primary purpose of extern "C" in C++?

    Answer: To prevent name mangling so C code can link to C++ functions

    extern "C" instructs the C++ compiler to use C linkage, preventing name mangling so the symbol can be called from C code.

  2. Which two techniques are commonly used to prevent multiple inclusions of a header file?

    Answer: Both #pragma once and #ifndef/#define/#endif

    Both the portable #ifndef/#define/#endif include guard pattern and the widely-supported #pragma once compiler extension prevent double inclusion.

  3. When calling a C library that allocates memory, how must that memory be freed in C++?

    Answer: Use free()

    Memory allocated by C library functions using malloc/calloc must be released with free(), not delete, to avoid undefined behavior.

  4. What does the __cplusplus predefined macro indicate?

    Answer: Whether code is compiled as C++ and which standard version is active

    The __cplusplus macro is set by C++ compilers to an integer value representing the active standard, such as 201703L for C++17.

  5. What is C++ name mangling?

    Answer: The compiler encoding of a function's full signature into its binary symbol name

    Name mangling encodes the full function signature (including parameter types) into the binary symbol name to support function overloading.

  6. How should a C++ function pointer be declared to be safely passed as a callback to a C library?

    Answer: As a free function or static member with extern "C" linkage

    C libraries require C-linkage function pointers; a free function or static member declared with extern "C" provides the correct calling convention.