Services
Back

Question:

Why are there underscores in the number 10_000_000?

How often asked: Rarely

Suggested by: ALittleMoron


Answer:

In integers and floating-point numbers, this is used to visually highlight the size of the number. It's easier to look at large numbers with this underscore because it's immediately clear what the number is.

You can also use an underscore to highlight numbers after the decimal point, like this: 10_000_000.000_000_001.


Interview answer explanation:

A fairly rare question and even somewhat useless. It's a rarely used language feature that doesn't even require separate learning. You see it once in someone else's code, and then you use it as needed.


External resources: