What is the difference between a double and an int in C++?
int stores whole numbers, while double stores floating-point (decimal) numbers.
What is the output of this code?
int x = 5;
if (x < 10) cout << "Small";
else cout << "Big";
Small (since 5 < 10).
How many times does this loop run?
int i = 1;
while (i <= 3) {
cout << i << " ";
i++;
}
3 times (1 2 3).
What will be the output of the following C++ expression?
int x = 5, y = 2;
cout << x / y;
2 (Integer division discards the decimal).
What will 'true && false || true' evaluate to?
true (&& happens first, so false || true → true).
What’s wrong with this for loop?
for (int i = 0; i < 5; i--)
cout << i << " ";
The loop never terminates because i-- decreases instead of increasing.
Convert the binary number 1011 to decimal.
11 (1×8 + 0×4 + 1×2 + 1×1 = 11).
What will be printed?
int num = 3;
switch (num) {
case 1: cout << "One"; break;
case 3: cout << "Three"; break;
default: cout << "Other";
}
Three
How many asterisks * will be printed?
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 2; j++) {
cout << "*";
}
}
6 (3 × 2).
What is the ASCII value of the character 'C'?
*Use an ASCII Table Online*
67
What does this program output?
string s = "hello";
s[0] = 'H';
cout << s;
Hello. (String indexing allows modification).
Why is incremental programming useful when writing loops?
It allows testing small sections of code step by step, making debugging easier.
What’s wrong with this code?
int num;
cout << "Enter a number: ";
cin >> num;
if (num = 10) {
cout << "Number is ten!";
}
The condition should be if (num == 10), because = is an assignment operator, not a comparison operator.
Rewrite this if-else statement as a conditional (?:) expression:
if (x > 0) result = "Positive";
else result = "Non-positive";
result = (x > 0) ? "Positive" : "Non-positive";
What will be printed?
enum Color {RED, GREEN, BLUE};
Color c = GREEN;
cout << c;
1 (Enumerations start at 0, so GREEN is 1).