Vars & I/O
Loops
Classes&Structures
Functions
Files & Pointers
100

What does the following code output?

int wage = 10;

cout << wage * 2;

100

What is short-circuit evaluation?

When logical expressions stop evaluating as soon as the result is known.

100

What keyword defines a class in C++?

class

100

What keyword starts a function declaration?

Return type (e.g., int, void)

100

 Which header is needed for file input/output?

<fstream>

200

What is the keyword used to declare a variable of type integer in C++?

int

200

What is wrong with this code?

if (x = 5) {

  cout << "Yes";

}

It uses assignment (=) instead of comparison (==)

200

What is an object?

An instance of a class.

200

What is the return type of this function?

int add(int a, int b) {

  return a + b;

}

int

200

What does this line do?

ifstream inFile("data.txt");

Opens the file data.txt for reading.

300

What header file is required to use cin and cout

<iostream>

300

Describe the difference between while and do-while loops.

do-while always runs at least once; while may not run at all.

300

 What does the public keyword mean in a class?

Members can be accessed from outside the class.

300

What is the purpose of parameters in functions?

They allow passing data into a function.

300

What is a pointer?

A variable that stores a memory address.

400

Explain the purpose of endl in output statements.

It inserts a newline character and flushes the output buffer.

400

 What is a potential risk of this loop?

while (true) {

  // some condition never changes

}

Infinite loop risk

400

What is a constructor?

A special function that initializes objects of a class.

400

How do you access the third element in a vector v?

 v.at(2)

400

What is the * operator used for in pointers?

Dereferencing — accessing the value at a memory address.

500

What is the result of the following code and why?

int wage;

cout << wage;

It outputs an undefined value because wage was declared but not initialized.

500

Write a for loop that counts down from 5 to 1.

for (int i = 5; i >= 1; i--) {

  cout << i;

}

500

Write a simple class Car with one public int member speed and no methods.

class Car {

public:

  int speed;

};

500

What is the difference between function overloading vs overriding?

Overloading is defining multiple functions with the same name but different parameter lists.

Overriding lets you define one or more tasks that will override the function defined in the base class or parent class. WHO can do this by calling virtual prototypes or inheriting the type declared in your base class.

500

What will this code output?

int x = 10;

int* ptr = &x;

cout << *ptr;

10

M
e
n
u