CPA-21-02 practice question 26 of 35
What happens when you attempt to compile and run the following code? #include using namespace std; int f(int a, int b); int main() { float b; b = f(20,10); cout
Full set: 257 questionsThe function f takes two integer parameters and returns an integer. When f(20, 10) is called, the expression a / b performs integer division (20 / 10), which evaluates to the integer 2. This integer is returned and then implicitly converted to a float (value 2.0f) when assigned to the variable b in main. The std::cout stream formats the float 2.0f and prints it as 2 without trailing decimal zeros by default.
B: Integer division of 20 by 10 results in 2, not 5. C: Integer division of 20 by 10 results in 2, not 10. D: Integer division of 20 by 10 results in 2, not 0.
- ISO/IEC 14882:2017 (C++17 Standard), Section 8.5.4 [expr.mul], Paragraph 4 (Integer division).
- ISO/IEC 14882:2017 (C++17 Standard), Section 7.3.8 [conv.fpint] (Floating-integral conversions).
- Bjarne Stroustrup, "The C++ Programming Language" (4th Edition), Chapter 10.5 (Implicit Type Conversion).
Keep practicing
Take the free CPA-21-02 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other CPA-21-02 practice questions
- Question 1What happens when you attempt to compile and run the following code? #include using names…
- Question 2What happens when you attempt to compile and run the following code? #include #include us…
- Question 3Which of the following statements are correct about an array? int tab[10];
- Question 4What happens when you attempt to compile and run the following code? #include #include us…
- Question 5What is the output of the program if characters 'h', 'e', 'l', 'l' , 'o' and enter are su…
- Question 6What happens when you attempt to compile and run the following code? #include using names…
