#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · EVERY ANSWER RUN AND CHECKED

Guess the Output: Can You Predict What This Code Prints?

32 tricky snippets in five languages. Read the code, pick the output, learn the rule.

  • 🐍 Python and JavaScript
  • ⚙️ C, C++ and Java
  • ✅ Answers verified by running

How to use the Guess the Code Output Quiz

  1. 1. Choose the length10 random code output questions, or all 32.
  2. 2. AnswerTap an option. You see straight away whether it's right, with a one-line reason.
  3. 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.

More free tools

See all free tools