How to use the Guess the Code Output Quiz
- 1. Choose the length10 random code output questions, or all 32.
- 2. AnswerTap an option. You see straight away whether it's right, with a one-line reason.
- 3. ReviewFinish to get your score and a list of every question with the correct answer.
The snippets
There are 11 Python, 11 JavaScript, 4 C, 3 Java and 3 C++ snippets. Each one is short and hides a rule that catches people out:
- Python: shared list references, mutable default arguments, floor division with negatives, slicing, truthy strings, starred unpacking and how strings sort.
- JavaScript: + vs - with strings, sort() without a compare function, typeof null, var in loops with timers, Promise vs setTimeout order, loose equality and this.
- C, C++ and Java: post-increment, sizeof a string, pointers, integer division, == vs equals() on strings, string joining order, references and virtual functions.
Every snippet was run with Python 3, Node.js, gcc, g++ and Java to confirm the answer, so you can trust the key.
A sample question explained
What does this Python print?
def f(a, items=[]):
items.append(a)
return items
f(1)
print(f(2))The answer is [1, 2], not [2]. A default value is created once, when the function is defined, so every call that doesn't pass items shares the same list. The usual fix is items=None and then if items is None: items = [] inside the function.
Questions like this appear in coding rounds because they test whether you know how a language really works. After each answer you get the rule in one line. Try predicting before you look at the options; then run the snippet yourself in the Python or JavaScript online compiler to see it happen.
Frequently asked questions
Which language versions were used to check answers?
Python 3, Node.js 22, gcc and g++ on Linux, and Java 21. Outputs are the same on other current versions.
Why does the JavaScript this question say undefined?
The function is called without an object in a normal (non-strict) script, so this is the global object, which has no x.
Can I pick one language?
Not yet. Each snippet shows its language above the code, and the score breaks down by language.
Is the guess the code output quiz free to take?
Yes. The guess the code output quiz lets you answer every question with no form. At your first score screen we ask for your name and WhatsApp number once; after that, the guess the code output quiz and all other Uncodemy tools stay open.