โ† All CPP Flashcard Decks

Syntax Fundamentals & Data Structures Flashcards

7 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 7 Syntax Fundamentals & Data Structures flashcards as text
  1. What does 'std::move' do to an object?

    Answer: Casts the object to an rvalue reference, enabling move semantics

    std::move is a cast to rvalue reference; it signals that the object's resources can be transferred rather than copied.

  2. Which STL data structure provides LIFO (Last-In, First-Out) behavior?

    Answer: std::stack

    std::stack implements LIFO semantics; elements are pushed and popped from the same end (top).

  3. What is the result of this expression in C++? ```cpp std::cout << (true + true + false); ```

    Answer: 2

    In arithmetic context, true converts to 1 and false to 0, so 1+1+0 = 2.

  4. What is a 'dangling pointer' in C++?

    Answer: A pointer that points to memory that has been freed or gone out of scope

    A dangling pointer points to memory that is no longer valid, such as after delete or when a local variable's scope ends.

  5. Which keyword is used to prevent a derived class from overriding a virtual function in C++11 and later?

    Answer: final

    The 'final' specifier prevents further overriding of a virtual function in derived classes.

  6. What is the time complexity of inserting an element at the front of a std::deque?

    Answer: O(1)

    std::deque supports O(1) amortized insertion at both front and back, unlike std::vector which is O(n) at the front.

  7. What does the 'explicit' keyword do when applied to a constructor?

    Answer: Prevents the constructor from being used for implicit type conversions

    The explicit keyword prevents the compiler from using that constructor for implicit single-argument conversions.