Which header must be included to use std::cout for console output in standard C++?
Cpp Cpa Types And Operators
Question · Easy
What does the following snippet print? #include <iostream> int main() { int x = 5; int y = 2; std::cout << x / y << " " << x % y; return 0; }
Question · Medium
Which statement about C++ identifiers is TRUE?
Tech Exam Prep Podcast
Listen on Spotify
Podcast
What does the following code print? #include <iostream> int main() { int a = 10; int b = 3; std::cout << a + b * 2; return 0; }
Which of the following is the correct way to declare a constant integer in C++?
What is the output of the following code? #include <iostream> int main() { int i = 5; std::cout << i++ << " " << ++i; return 0; }
Question · Hard
Which of these is NOT a fundamental built-in type in C++?
What does this snippet print? #include <iostream> int main() { bool b = 5; std::cout << b << " " << !b; return 0; }
Which statement about a C++ literal like 3.14 is TRUE?
What does this code print? #include <iostream> int main() { int a = 7; int b = 4; std::cout << (a > b ? a : b); return 0; }
Which output does the following produce? #include <iostream> int main() { int x = 5; int y = 2; double z = static_cast<double>(x) / y; std::cout << z; return 0; }
What is the output of this snippet? #include <iostream> int main() { int x = 10; x += 5; x *= 2; std::cout << x; return 0; }
What does this code print? #include <iostream> int main() { std::cout << (5 == 5) << " " << (5 != 5); return 0; }
Which of these is the correct C++ logical AND operator?
What is the output of the following program? #include <iostream> int main() { int x = 5; int y = ++x + x++; std::cout << x << " " << y; return 0; }
How is a single-line comment written in C++?
What is the output of the following code? #include <iostream> int main() { int a = 12; int b = 5; std::cout << (a & b) << " " << (a | b); return 0; }
What does the following loop print? #include <iostream> int main() { for (int i = 0; i < 4; i++) { std::cout << i; } return 0; }
Cpp Cpa Control Flow
Which keyword exits the closest enclosing loop or switch in C++ immediately?
What does this code print? #include <iostream> int main() { int n = 0; while (n < 3) { std::cout << n; n++; } return 0; }
What is the output of this snippet? #include <iostream> int main() { int i = 0; do { std::cout << i; i++; } while (i < 0); return 0; }
What does this program print? #include <iostream> int main() { for (int i = 0; i < 5; i++) { if (i == 2) continue; std::cout << i; } return 0; }
What does this switch print when called with x = 2? #include <iostream> int main() { int x = 2; switch (x) { case 1: std::cout << "A"; case 2: std::cout << "B"; case 3: std::cout << "C"; default: std::cout << "D"; } return 0; }
Which of the following statements about exception handling in C++ is TRUE?
What does this program print? #include <iostream> #include <stdexcept> int main() { try { throw std::runtime_error("oops"); } catch (const std::runtime_error& e) { std::cout << "caught"; } catch (...) { std::cout << "generic"; } return 0; }
What does this code print? #include <iostream> int main() { int i = 10; while (i > 0) { std::cout << i << " "; i -= 3; } return 0; }
What is the output of this snippet? #include <iostream> int main() { int i = 0; for (; i < 3; ) { std::cout << i; i++; } return 0; }
Which statement about a switch statement in C++ is FALSE?
What does this print? #include <iostream> int main() { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 2; j++) { std::cout << i * j << " "; } } return 0; }
What does this code print? #include <iostream> int main() { int x = 5; if (x > 0) if (x > 10) std::cout << "A"; else std::cout << "B"; return 0; }
What is the output of the following code? #include <iostream> void greet() { std::cout << "Hello"; } int main() { greet(); greet(); return 0; }
Cpp Cpa Functions
What does this code print? #include <iostream> int add(int a, int b = 10) { return a + b; } int main() { std::cout << add(5) << " " << add(5, 20); return 0; }
Which mechanism allows two functions to share a name in the same scope but accept different parameter types?
What does this code print? #include <iostream> void modify(int x) { x = 100; } int main() { int a = 5; modify(a); std::cout << a; return 0; }
What does this snippet print? #include <iostream> void modify(int& x) { x = 100; } int main() { int a = 5; modify(a); std::cout << a; return 0; }
What does this recursive function print when called as factorial(4)? #include <iostream> int factorial(int n) { if (n <= 1) return 1; return n * factorial(n - 1); } int main() { std::cout << factorial(4); return 0; }
Which function signature pair is a valid example of overloading?
What is the output of this code? #include <iostream> int sum(int a, int b, int c = 0) { return a + b + c; } int main() { std::cout << sum(1, 2) << " " << sum(1, 2, 3); return 0; }
What does this code print? #include <iostream> int count() { static int n = 0; return ++n; } int main() { std::cout << count() << count() << count(); return 0; }
Which preprocessor directive includes the contents of another file?
What does this code print? #include <iostream> #define SQUARE(x) ((x) * (x)) int main() { int n = 4; std::cout << SQUARE(n + 1); return 0; }
Which keyword suggests to the compiler that a function should be expanded inline at the call site?
What is the output of this code? #include <iostream> int arr[] = {10, 20, 30, 40, 50}; int main() { std::cout << arr[2] << " " << arr[4]; return 0; }
Cpp Cpa Pointers
What does this snippet print? #include <iostream> int main() { int x = 42; int* p = &x; std::cout << *p; return 0; }
Given int a[] = {1, 2, 3, 4}; and int* p = a; what is the value of *(p + 2)?
What does this code print? #include <iostream> int main() { int* p = new int(7); std::cout << *p; delete p; return 0; }
Which operator is used to release memory allocated with new[]?
Loading more…