1. Which C++ standard is usually described as the start of "modern C++"?
- C++11
- C++98
- C++03
- C++23
जवाब देखें
जवाब: C++11
C++11 introduced auto, lambdas, move semantics and smart pointers, transforming everyday C++.
C++ कोर्स के 25 सवाल, हर सवाल के सही जवाब और explanation के साथ। जवाब देखने से पहले ख़ुद सोचें।
जवाब: C++11
C++11 introduced auto, lambdas, move semantics and smart pointers, transforming everyday C++.
जवाब: Combines object files and libraries into an executable, resolving references between them
The linker resolves symbols across object files and libraries to produce the final binary.
जवाब: Fails to compile because it is a narrowing conversion
List initialisation forbids narrowing conversions, catching accidental data loss.
जवाब: Its enumerators are scoped and do not implicitly convert to integers
Scoped enums avoid name clashes and accidental integer conversions.
जवाब: By const reference
const reference avoids copying while guaranteeing the function will not modify the argument.
जवाब: It violates the One Definition Rule: the function is defined twice in the program
Each translation unit gets its own definition, so the linker finds duplicate symbols.
जवाब: Its destructor runs automatically and frees its memory
Automatic objects are destroyed at the end of their scope, and the vector frees its buffer.
जवाब: A reference must be initialised and always refers to the same object
References are aliases bound at initialisation; they cannot be null or reseated.
जवाब: std::unique_ptr
unique_ptr has exactly one owner and is as cheap as a raw pointer.
जवाब: Members are initialised directly instead of being default-constructed then assigned, and const or reference members require it
Initialiser lists initialise members once, correctly, before the body runs.
जवाब: It casts its argument to an rvalue reference so that a move operation can be chosen
std::move is a cast; the move constructor or assignment performs the actual transfer.
पाठ: Copy and Move Semantics and the Rule of Zero, Three and Five
जवाब: Copying a derived object into a base-class value, losing the derived part
Base-class values hold only the base part; use references or pointers for polymorphism.
जवाब: std::vector
vector is contiguous, cache-friendly and efficient for most workloads.
जवाब: The lambda captures total by reference, so changes affect the original variable
& captures by reference; without & the variable would be copied into the lambda.
जवाब: std::optional<int>
std::optional makes absence explicit in the type instead of relying on magic values.
पाठ: Vocabulary Types: optional, variant, string_view and span
जवाब: When it is used with specific types (instantiation)
Templates are instantiated for each set of template arguments actually used.
जवाब: They state template requirements explicitly, giving clearer interfaces and error messages
Concepts document and check requirements on template arguments at the call site.
जवाब: Every call is evaluated at compile time
consteval functions are immediate functions: each call must produce a compile-time constant.
जवाब: By const reference
Catching by const reference avoids slicing and unnecessary copies.
जवाब: It is a data race, which is undefined behaviour
Unsynchronised concurrent writes (or a write with a read) are data races and undefined behaviour.
जवाब: AddressSanitizer
AddressSanitizer instruments memory accesses to catch these errors.
जवाब: With target_include_directories() on the specific target
Target-based commands keep settings attached to the targets that need them.
जवाब: The initial value's type sets the accumulator type; 0 would accumulate in int and could overflow
accumulate returns and accumulates in the type of the initial value.
जवाब: A smart pointer such as std::unique_ptr
Smart pointers make ownership explicit and release resources automatically.
जवाब: It is in a valid but unspecified state and can be assigned a new value or destroyed
Moved-from standard objects remain valid; you may reassign or destroy them.