Object Oriented Programming Using C Plus Plus - Study Mode

[#496] You have assigned the address of Value to the pointer P, Which statement will display the value stored in Value?
Correct Answer

(D) cout<<*P

[#497] The use of the break statement in a switch statement is
Correct Answer

(A) optional

Explanation

Solution: Correct Answer: A: optional Here's why: In a `switch` statement, the `break` statement is optional . How a `switch` works (Simplified): A `switch` statement checks a variable against different `case` values. If a `case` matches, the code under that `case` starts executing. `break`'s role: The `break` statement tells the program to immediately exit the `switch` statement . What happens without `break`? If you *don't* include a `break` after a `case`, the program will "fall through" to the next `case` and continue executing code there, even if that next `case` doesn't match the original variable's value. This "fall-through" behavior can be useful in some situations, but often you want to execute only the code associated with a single `case`. Example: Imagine a traffic light. `switch (trafficLightColor)` { `case "red":` `Stop()
` `break
` // Without this, it might also execute the "yellow" code! `case "yellow":` `SlowDown()
` `break
` `case "green":` `Go()
` `break
` `}` So, while `break` is very common and important for controlling the flow of execution in a `switch`, it's not required by the C++ language . The program will still compile and run (though perhaps not as intended) without it.

[#498] The statement double total = 0.0
performs _____
Correct Answer

(B) initialization

[#499] Which of the following creates an animal object named dog?
Correct Answer

(B) animal dog

[#500] Which of the following statements creates a named constant called driverAge whose value is 16?
Correct Answer

(B) const short driverAge = 16