If two functions have the same name but different parameter lists, it's called ______.
- Constructor Overloading
- Function Overloading
- Method Overloading
- Operator Overloading
If two functions in a class have the same name but differ in the number or type of parameters, it's referred to as "Function Overloading." This allows you to create multiple functions with the same name, providing flexibility and clarity when using them in different contexts.
For a function whose return type is deduced at the time of its invocation, the keyword ______ is used.
- deduce
- infer
- decltype
- auto
For a function whose return type is deduced at the time of its invocation, the keyword 'auto' is used. This is part of the C++11 feature where the compiler determines the return type based on the function's implementation. It allows for more flexible and concise code.
How would you declare a variable pi that holds the value of pi up to several decimal places?
- decimal pi = 3.14159265359;
- double pi = 3.14159265359;
- float pi = 3.14;
- int pi = 3;
In C++, to store the value of pi up to several decimal places, you would typically use the double data type. The double data type provides greater precision compared to float or int, making it suitable for representing the value of pi with more decimal places.
In C++, the conditional operator ______ is a ternary operator.
- ?:
- if-else
- switch
- while
In C++, the conditional operator "?:" is commonly known as the ternary operator. It is a shorthand way to write conditional expressions and is often used to assign values based on a condition. The operator takes three operands: a condition, a value if the condition is true, and a value if the condition is false.
The main function's standard signature returns an integer and accepts ______ arguments
- four
- one
- three
- two
The standard signature for the main function in C# and many other programming languages returns an integer and accepts two arguments, typically string[] args for command-line arguments.
In a switch statement, each case ends with the ______ keyword to prevent fall-through.
- break
- continue
- goto
- return
In a switch statement in C++, each "case" ends with the "break" keyword. The "break" statement is crucial in switch statements to prevent fall-through, meaning that once a case is matched and its code block is executed, the program exits the switch block.
What will be the flow of control in a switch statement if there is no break keyword at the end of a case?
- It will continue to execute the next case
- It will return to the main function
- It will terminate the switch statement
- It will throw an error
In C/C++, if there's no break statement at the end of a case in a switch statement, the control will continue to execute the next case statements without any regard for the case conditions. This behavior is known as "fall-through." It's important to use break statements to avoid unintended fall-through.
To ensure portability of your C++ program across different platforms, you can use data types like ______ which have a fixed size.
- auto
- double
- float
- int32_t
To ensure portability, you can use fixed-size integer data types like int32_t from the header. These types guarantee a consistent size across platforms, making your code less dependent on the underlying system's architecture. This is crucial when dealing with binary data or network protocols.
How does function overloading interact with functions that have default arguments?
- Function overloading and default arguments can be used together.
- Function overloading cannot be used with functions having default arguments.
- Function overloading doesn't affect functions with default arguments.
- Function overloading overrides default arguments.
Function overloading can be used in conjunction with functions that have default arguments. In C++, you can have multiple functions with the same name but different parameter lists (overloads), and some of these overloads can have default arguments. The compiler selects the appropriate function based on the arguments provided.
Emily is writing a program to calculate the area of a circle. Which data type should she use to store the calculated result for better precision?
- decimal
- double
- float
- int
Emily should use the 'double' data type for better precision in calculations involving decimal numbers, such as the area of a circle. 'Double' provides a higher level of precision compared to 'float' and is suitable for scientific and engineering calculations.