C and C++ Coding Flashcards
7 cards from real Online Coding Lessons practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 C and C++ Coding flashcards as text
In C, what does the sizeof operator return for an int on most modern 64-bit systems?
Answer: 4 bytes
An int is typically 4 bytes on most modern platforms regardless of 32- or 64-bit.
Which C++ keyword is used to prevent a member function from modifying the object's state?
Answer: const
Marking a member function const guarantees it will not modify the object's members.
What is the result of the C expression 7 / 2 when both operands are integers?
Answer: 3
Integer division in C truncates the fractional part, yielding 3.
In C++, which container provides automatic dynamic resizing and contiguous storage?
Answer: std::vector
std::vector stores elements contiguously and grows automatically as needed.
What does the C standard library function malloc return when allocation fails?
Answer: NULL
malloc returns NULL when it cannot allocate the requested memory.
Which operator is used to access a struct member through a pointer in C?
Answer: ->
The arrow operator -> dereferences a pointer and accesses the member in one step.
In C++, what does the 'new' operator do that 'malloc' does not?
Answer: Calls the object's constructor
new allocates memory and invokes the constructor, while malloc only allocates raw bytes.