Lisa is trying to divide 15 by 2 and get an integer result. Which operator should she use in C++?
- /
- %
- //
- ÷
In C++, to perform integer division and get the quotient as an integer result, Lisa should use the '/' operator. The '%' operator is used to calculate the remainder in integer division. The other options are not valid C++ operators for division.
In C++, passing large structures or classes to functions is typically done by _______ to avoid expensive copy operations.
- pointers
- value
- integers
- operators
Passing large structures or classes by value results in copy operations, which can be expensive in terms of performance. To mitigate this, C++ developers often pass large data structures using pointers or references, allowing the function to access the original data without copying.
The function _______ is used to merge two sorted ranges in the C++ STL.
- combine
- concatenate
- merge
- join
The merge algorithm in C++ STL is used to merge two sorted ranges into a single, sorted range. Both input ranges should be sorted for the merge algorithm to work correctly.
The result of 5.5 + 2.5 in C++ is _______.
- 8
- 7.5
- 8
- 7
In C++, the addition of two floating-point numbers (like 5.5 and 2.5) will result in another floating-point number, which is 8.0 in this case.
Which of the following is not a type of iterator in C++ STL?
- Random access
- Bidirectional
- Dynamic
- Forward
The C++ STL provides several types of iterators like random access, bidirectional, and forward iterators. However, there is no iterator type named "Dynamic." Iterators are powerful tools in STL, allowing operations like traversal, reading, and writing to elements of container objects.
The function signature in C++ includes the function name and the _______.
- return type
- class name
- library
- parameters
A function signature in C++ is determined by its name and its parameter list. The return type is not considered a part of the function's signature.
Imagine you are developing a system where you need to represent a fixed set of constant integral values that represent different states, and you want to restrict the variables to only allow these states. Which C++ feature would be most appropriate to use?
- Class
- Enum
- Union
- Template
Enums, short for enumerations, allow the definition of a type that can hold a set of integral constants. They provide a way to assign names to the integral constants which makes the code more readable and maintainable.
To insert an element into a C++ list at a specified position, you should use the _______ function.
- push
- emplace
- put
- insert
The insert function in C++ STL is used to insert elements at a specific position in a list. emplace is also used for insertion, but it constructs the object in-place, while insert just places a copy or a move of the object.
The _______ keyword is used to include standard libraries in a C++ program.
- import
- include
- namespace
- return
In C++, the "include" keyword is used to include header files, which contain the declarations for the standard libraries. It's vital for utilizing predefined functions and classes, thus facilitating easier and more efficient coding.
Which keyword is often advised against using due to its potential to make code less readable and maintainable?
- class
- public
- goto
- private
The goto keyword allows for arbitrary jumps in code, which can make the code's flow hard to follow, leading to decreased readability and maintainability. Although it's available in C++, its use is generally discouraged in modern programming practices.