PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 49


What is the expected behavior of the following code?

Show Answer
Correct Answer: C

The code initializes a string '123' and a variable 'dummy' set to 0. It then iterates over the reversed string, converts each character to an integer, and adds it to 'dummy'. The reversed string is '321', so the code performs the following operations: dummy += 3 (dummy is now 3), dummy += 2 (dummy is now 5), dummy += 1 (dummy is now 6). Finally, it prints the value of 'dummy', which is 6. Therefore, the correct answer is output 6.

Discussion

1 comment
Sign in to comment
DKAT2023Option: C
Jul 12, 2024

C is correct