The ASCII value of 'A' in decimal is _______.
- 64
- 65
- 66
- 67
The ASCII value for the uppercase letter 'A' is 65 in decimal. ASCII (American Standard Code for Information Interchange) assigns each character a unique number between 0 and 127.
The break statement cannot be used within a _______.
- function
- switch statement
- class
- if condition
The break statement is primarily used to terminate loops and switch statements. Using a break outside these constructs, like directly inside a function without a loop or switch, would result in a compilation error as it wouldn't have a clear context to operate within.
Which bitwise operator is used to flip the bits (change 1s to 0s and vice versa) of a binary number?
- &
- |
- ^
- ~
The ~ operator is the bitwise NOT operator in C++. It inverts each bit of a number, changing 1s to 0s and 0s to 1s. & is the bitwise AND, | is the bitwise OR, and ^ is the bitwise XOR operator.
The standard namespace used commonly in C++ is _______.
- conio
- iostream
- stdlib
- std
In C++, the "std" stands for the standard namespace. A namespace is a declarative region that provides a scope to the identifiers inside it. Using the "std" namespace, we can access features of the C++ Standard Library without prepending their names with std:: each time.
How does the goto statement alter the flow of control in a C++ program?
- It repeats the loop indefinitely.
- It skips to the next iteration of a loop.
- It transfers control to a labeled statement in the code.
- It exits the program immediately.
The goto statement in C++ provides an unconditional jump from the goto to a labeled statement found elsewhere in the code. Although it allows for more flexibility in controlling the flow, its overuse or misuse can make the code less readable and more prone to errors. The modern programming paradigm usually discourages its use.
What is the correct syntax for declaring a function that returns an integer?
- int functionName;
- functionName: int;
- int functionName()
- int: functionName()
In C++, to declare a function that returns an integer, the correct syntax is "int functionName()". The type "int" signifies that the function's return type is an integer, and the parentheses "()" indicate it's a function declaration. Actual implementation or body of the function would follow the declaration.
In C++11 and later, the keyword _______ can be used in a range-based for loop to avoid copying elements.
- const
- mutable
- auto
- static
In C++11's range-based for loop, the const keyword ensures that elements are not modified, effectively preventing unintentional copies or modifications to the elements.
What is the potential problem with the following loop: while(true) { /* code */ }?
- It will cause a compile-time error.
- It can potentially result in an infinite loop.
- The code inside will never execute.
- It will slow down the computer significantly.
The loop while(true) will continue to execute indefinitely since the condition is always true. This can potentially lead to an infinite loop, consuming CPU resources, and making the program unresponsive unless externally interrupted.
You are designing a class that will be widely used across a large project. The class will often be copied and assigned to other instances. What considerations related to constructors and assignment operators should be taken into account to ensure efficient and correct operation?
- Use of shallow copy.
- Implementing move semantics.
- Avoid using constructors.
- Only use private member variables.
When a class is frequently copied or assigned, it's crucial to consider the efficiency of these operations. Move semantics, introduced in C++11, allow resources to be "moved" from one object to another, without making a copy. This can greatly improve performance. Shallow copy can lead to issues like double deletion, and avoiding constructors or only using private members doesn't address the efficiency of copying or assignment.
Which of the following best describes the concept of abstraction in C++?
- Hiding complex reality while exposing only the necessary.
- Protecting data from unauthorized access.
- Using single inheritance.
- Creating multiple instances of an object.
Abstraction in C++ refers to the concept of hiding the complicated reality of an object while only exposing operations relevant for that object. This allows for simplifying complex systems by breaking them down into smaller, more manageable parts, enabling developers to focus on high-level functionalities.