What is the type of the character literal 'A' in C++?
In C++ 'A' is a char, so sizeof('A') is 1 and overloads taking char are chosen. In C it is an int.
Basic Syntax and Data Types · Exercise 1 of 4
Twenty multiple-choice questions on C++ program structure, namespaces, data types, initialization, auto, const and constexpr. Pick an option to check your answer instantly.
What is the type of the character literal 'A' in C++?
In C++ 'A' is a char, so sizeof('A') is 1 and overloads taking char are chosen. In C it is an int.
What is static_cast<double>(a) used for?
static_cast performs well-defined conversions (numeric types, up/down class hierarchies) and is easy to find in code. reinterpret_cast is for low-level pointer reinterpretation.
Which statement about std::cerr is true?
Use std::cerr for error messages: it goes to stderr (which can be redirected separately from stdout) and is not buffered. std::clog also writes to stderr but is buffered.
In which order are these stages performed when building a C++ program?
#include and macros are handled first, then the code is compiled and assembled into object files, and finally the linker joins object files and libraries.
Which escape sequence inserts a horizontal tab in a string?
\t is a tab, \n a newline, \b a backspace and \a the alert (bell) character.
Which of the following is not a fundamental (built-in) type?
std::string is a class from the standard library (<string>). Fundamental types are the arithmetic types, void and std::nullptr_t.
Inside a function, what does int x{}; contain?
Empty braces value-initialize: zero for numbers, false for bool, nullptr for pointers. int x; without braces would be uninitialized.
What does using Score = int; do?
A type alias does not create a new type: a Score is an int. It documents meaning and makes later changes (e.g. to double) one-line edits.
What value does bool b = 5; store?
Any non-zero number converts to true and zero to false. Printing b with cout shows 1.
What does the C++ standard say about int x = INT_MAX; x = x + 1;?
Signed overflow is undefined behaviour – the result may look like wrap-around, or the optimizer may assume it never happens and remove checks. Unsigned types wrap; compile with -fsanitize=undefined to catch signed overflow while testing.
Timed online tests with instant scores and explanations.