Which data type should be used to represent both positive and negative values
A signed integer
Which C++ element includes a return type, a name, parentheses, and a code block in curly braces?
Function
True/False: A function needs to be declared before all use.
True
What does it return?
float x = 7.7;
int y = x;
return y;
7
True/False: Company does not use C++ exceptions.
True, use error codes and assertions instead.
Which of the following is not a primitive (built-in) type in C++?
a. int
b. string
c. bool
d. char
e. void
String
What is the return type of a constructor function?
Nothing
what is the scope of a protected member variable in C++
Class and its derived classes
What does this return?
int x = 7;
int &y = x;
y = 21;
return x;
21
Which of these is a pointer to an object that has multiple owners: std::unique_ptr or std::shared_ptr
std::shared_ptr
Are C++ identifiers case sensitive?
Yes, ‘Cat’, ‘cAT’ and ‘CAT’ are different identifiers
What is the default access level of a member variable in a C++ class?
Private
Two or more functions have the same name but the arguments are different. This is an example of
Function Overloading or Polymorphism
What is wrong with this code? Assume the functions work correctly
int LOTS = 10;
int amountOfFun {};
while ( amountOfFun < LOTS ) {
amountOfFun = 0;
goToCamp();
writeNeatCode();
playGames();
earnPoints();
++amountOfFun;
}
cout << "We've had a lot of fun! Time to go home" ;
Infinite Loop
What is wrong with this code according to Company's style guide? How would you fix it
int i;
i = f();
Initialization separate from declaration. Correct way int i = f();
What is the purpose of the auto keyword in C++?
The auto keyword in C++ is used to specify that the data type of a variable should be automatically deduced by the compiler at compile-time. This feature is called "type inference".
What is the difference between a static and a non-static member function in C++?
Static members are not destroyed when the control goes out of scope.
Which type of inheritance allows a derived class to inherit from multiple base classes.
Multiple inheritance
How many lines does this print?
char* s {“String”};
for(const auto& c:s)
cout << c << “\n”;
7
What is wrong with a variable name “tableName” used in a function
The names of variables (including function parameters) and data members are all lowercase, with underscores between words. Right name would be table_name. Additionally data members of a class should also end with an underscore like table_name_
What is the purpose of the const keyword in C++?
The const keyword in C++ is used to indicate that a variable's value cannot be modified after initialization.
Which member function in a class is invoked automatically whenever an object is going to be destroyed.
Destructor
Which C++ construct is used to define a generic function or class that can operate on different data types.
Template
What is the difference between the initialization of Y and Z?
constexpr int square(int x) {
return x * x;
}
int main() {
constexpr int y = square(5);
int z = square(6);
return 0;
}
y is evaluated at compile-time, z is evaluated at runtime
Constant Variables whose values never change during the duration of the program should be declared as const or constexpr and their name should start with a ___?
k
Example: kEpsilon = 1e-6;