🌍 C++ Programming · flashcards

C++ Programming Basic Syntax Flashcards

50 question-and-answer cards covering Basic Syntax as it is examined in C++ Programming. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
12Syllabus topics
~173Chars per answer
FreePrice

24 sample cards from the Basic Syntax deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What is the arithmetic effect of the left shift `x << n` on a non-negative integer?

    Left-shifting by $n$ bits multiplies the value by $2^{n}$ (assuming no overflow). For example, $3 << 2 = 3 \times 2^{2} = 12$.

  2. What is the arithmetic effect of the right shift `x >> n` on a non-negative integer?

    Right-shifting by $n$ bits performs integer division by $2^{n}$, discarding the low bits. For example, $20 >> 2 = \lfloor 20 / 2^{2} \rfloor = 5$.

  3. What does the bitwise NOT operator `~` do, and what is `~5` for a signed 8-bit representation?

    `~` flips every bit (one's complement). For a signed value, $\texttt{\char`\~}x = -x - 1$, so `~5` $= -6$.

  4. What is the difference between bitwise AND `&` and logical AND `&&`?

    `&` operates bit-by-bit on the binary representations of its operands (e.g. $6 \,\&\, 3 = 2$), while `&&` treats operands as booleans and returns a single `true`/`false` with short-circuiting.

  5. What is the simple assignment operator, and name three compound assignment operators.

    The simple assignment is `=`. Compound assignments combine an operation with assignment, e.g. `+=`, `-=`, `*=`, `/=`, `%=`, `&=`, `|=`, `^=`, `<<=`, `>>=`. For example `x += 3` means `x = x + 3`.

  6. What does the compound assignment `x <<= 2` do?

    It left-shifts `x` by 2 bits and stores the result back in `x`, equivalent to `x = x << 2`, i.e. multiplying `x` by $2^{2} = 4$.

  7. What is the associativity of the assignment operator `=` in C++, and what does `a = b = c` do?

    Assignment is right-associative, so `a = b = c` is evaluated as `a = (b = c)`: `c` is assigned to `b`, and that result is then assigned to `a`.

  8. What does the `sizeof` operator return, and is it evaluated at compile time or run time?

    `sizeof` returns the size in bytes of a type or object as a `size_t`. It is a compile-time operator (its operand is not evaluated), e.g. `sizeof(int)` is typically $4$.

  9. Describe the ternary conditional operator `?:` and its general syntax.

    It is the only ternary operator in C++: `condition ? expr1 : expr2`. If `condition` is true it evaluates to `expr1`, otherwise to `expr2`. Example: `int max = (a > b) ? a : b;`.

  10. What do the address-of `&` and dereference `*` operators do when used as unary operators?

    Unary `&x` yields the memory address (a pointer) of `x`; unary `*p` dereferences a pointer `p` to access the object it points to. They are inverse operations.

  11. What is the purpose of the scope resolution operator `::` in C++?

    `::` accesses a name within a specific scope: a namespace member (`std::cout`), a class's static/member definition (`Class::member`), or the global scope (`::x` when a local hides it).

  12. What is the general syntax and behavior of an `if-else` statement?

    Syntax: `if (condition) { /*A*/ } else { /*B*/ }`. If `condition` evaluates to `true`, block A runs; otherwise block B runs. The `else` clause is optional.

  13. How does an `else if` ladder work, and how many of its blocks execute?

    An `else if` ladder chains conditions: `if(c1){} else if(c2){} else {}`. Conditions are tested top to bottom; the block of the first true condition runs and the rest are skipped, so at most one block executes.

  14. In C++, which rule resolves the 'dangling else' ambiguity?

    An `else` always binds to the nearest preceding unmatched `if` within the same block. Braces `{}` should be used to force a different association.

  15. What is the required syntax of a `switch` statement in C++?

    `switch(expr){ case const1: statements; break; case const2: statements; break; default: statements; }`. The `expr` must be an integral or enum type, and each `case` label must be a compile-time constant.

  16. What is 'fall-through' in a C++ `switch` statement?

    If a `case` block lacks a `break`, execution continues into the next `case`'s statements (fall-through). This is sometimes intentional for grouping cases but is a common source of bugs when accidental.

  17. What is the role of the `default` label in a `switch`, and is it required?

    `default` runs when no `case` label matches the switch expression. It is optional; if omitted and no case matches, the `switch` does nothing. It need not be placed last.

  18. Why can't a `switch` statement branch on a `float`, `double`, or `string` in C++?

    A `switch` requires an integral or enumeration expression and case labels that are integral constant expressions. Floating-point and `std::string` values are not integral constant expressions, so they are disallowed.

  19. What are the four parts of a C++ `for` loop and their execution order?

    Syntax: `for(init; condition; update) { body }`. Order: `init` runs once; then `condition` is tested — if true, `body` runs, then `update` runs, and the condition is re-tested; the loop ends when `condition` is false.

  20. How does a `while` loop differ from a `do-while` loop in C++?

    A `while` loop tests its condition before the body, so the body may run zero times. A `do-while` loop tests the condition after the body, guaranteeing the body runs at least once.

  21. What is the required syntax of a `do-while` loop, including punctuation?

    `do { body } while (condition);` — note the trailing semicolon after the `while(condition)`, which is mandatory and distinguishes it syntactically from a plain `while` loop.

  22. What is the difference between the `break` and `continue` statements inside loops?

    `break` immediately terminates the entire loop and transfers control after it. `continue` skips the rest of the current iteration and jumps to the loop's next condition test (and update step, in a `for` loop).

  23. What is a range-based `for` loop in C++11, and give its syntax.

    It iterates directly over elements of a container/array: `for (auto element : container) { ... }`. Using `auto&` binds by reference to allow modification and avoid copies.

  24. How do you write an intentional infinite loop in C++ using `for` and using `while`?

    Using `for`: `for(;;) { ... }` (all three parts omitted). Using `while`: `while(true) { ... }`. Both loop forever until an internal `break`, `return`, or exception exits them.

What this deck covers

The Basic Syntax deck follows the C++ Programming Basic Syntax syllabus — 3 chapters and 12 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 16.7 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 173 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Basic Syntax flashcards FAQ

How many Basic Syntax flashcards are in this C++ Programming deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these C++ Programming flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Basic Syntax cards cover?

They follow the C++ Programming Basic Syntax syllabus — 3 chapters and 12 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.