Your program prints 0 where you expected 0.98. The line looks right, the variable holds the number you gave it, and the division is written the way you would write it on paper. Nothing on the screen explains the answer.
A variable looks like a label, and that picture misleads. The name is yours, but the value sits in a place the machine owns, and the type you chose when you declared it decides how much room that place has and which numbers fit inside it. Once you see the place, wrong answers stop looking random.
What follows traces one variable from its name to its address, watches its bytes change when the value changes, and works through the traps that come from the type, the scope, and the lifetime. All the numbers come from a program I ran while writing, labelled as single runs.
What a variable is?
A variable is a name that refers to a value held in a memory location. That sentence carries two parts, and both matter: the name, which is for humans, and the address, which is for the machine. One name can hold more than one value: what an array is shows a row of values under a single name, reached by number.
When you write int age = 25 in C, the compiler records age in a table beside an address, then sets aside 4 bytes at that address and stores the number 25 there. The program works with the address from then on, and the name exists so you can read the code. Building that table is one of the jobs how a compiler works covers: turning names into addresses before the program ever runs.
A math variable stands for an unknown number. A programming variable stands for a place whose contents change. The box picture helps for a minute: a labelled box that holds one thing at a time. It breaks down the moment you ask where the box sits, how big it is, or what happens to the contents when the program ends.
At the lowest level the name disappears entirely. Assembly language has addresses and registers, nothing else. The name-to-address step is the compiler’s work, and what assembly language is shows the level where names stop existing.
A variable is three things: an address, a size, and a value
For this run, gcc 13.3.0 compiled a short C program that printed one variable’s address, size, and bytes. Python 3.12.3 ran the matching check from the other side.
It declared int age = 25, printed its address and size, read the four bytes at that address, then set age to 26 and printed all three again. The table holds the output, one run’s numbers.
| Variable | Address | Size | Value (bytes) |
|---|---|---|---|
| age | 0x7ffe26f8299c | 4 bytes | 25 (19 00 00 00) |
| age after age = 26 | 0x7ffe26f8299c | 4 bytes | 26 (1a 00 00 00) |

The address did not move, the size did not change, and the bytes changed from 19 to 1a in the first cell, because 25 is 0x19 and 26 is 0x1a in hexadecimal. The name stayed glued to one address while the value changed in place. That is the mechanism of reassignment: a new value written over the old bytes at the same address. Those bytes are binary values, and the way a machine reads them is how binary code works.
If the name exists for humans alone, does the computer ever see it? No. After compiling, the name is gone from the running program, and the processor works with the address alone. A debugger can show the name because it reads the table the compiler saved beside the program.
Python shows the mechanism with the roles reversed. The name x pointed at the object 25, and after x = 26 it pointed at a different object: id(x) moved from 11760552 to 11760584. In C the name stays glued to one address; in Python the name rebinds to a new object. The id function in the Python docs reports the identity of the object a name points at.
The address surprised me more than the bytes did. It changes from run to run, so an address printed here belongs to one run alone. The size stays 4 bytes and the byte pattern does not change. Addresses vary by run; the mechanism does not.
Declare it, assign it, change it
Three operations cover nearly everything a variable does. Declaration creates it and reserves its space. Assignment stores a value. Reassignment replaces the stored value with a new one.
Declaration is the promise. int age tells the compiler to set aside 4 bytes and remember the name age beside their address. Nothing is stored yet unless you add an initial value, and a declared-but-empty variable holds whatever the memory already contained.
Assignment is the store. age = 25 writes the bytes for 25 into those 4 bytes. The equals sign assigns; it doesn’t test equality. That single fact causes more beginner bugs than any other line of code.
Take a = 3, then b = a, then a = 5. The second line copies the value 3 into b. The third line changes a alone. b stays 3, because assignment copies a value and doesn’t tie two names together.
count = count + 1 looks circular until you read the right side first. The machine reads the current value of count, adds 1, and stores the result back in the same place. A loop does that once per pass, which is what iteration in programming is: one variable, changed a little per pass, until a condition stops the loop.
The type decides the size and the range
The type is the contract. It fixes how many bytes the variable occupies, which values fit, and what arithmetic means for it. Change the type and the digits behave differently.
| Type | Size (measured) | What it holds |
|---|---|---|
| char | 1 byte | One small number or character |
| short | 2 bytes | Integers to about 32,000 |
| int | 4 bytes | Integers to about 2.1 billion |
| long | 8 bytes | Integers to about 9.2 quintillion |
| float | 4 bytes | Decimals, about 7 digits of precision |
| double | 8 bytes | Decimals, about 16 digits of precision |
| long double | 16 bytes | Decimals, widest range |

Those sizes come from one C compiler on one run. The C standard lets long be 4 bytes on some platforms, so treat the table as one implementation’s sizes. The pattern holds everywhere: a bigger type costs more bytes and holds a wider range.
A 32-bit signed int holds -2,147,483,648 to 2,147,483,647. That range comes from 32 bits with one bit for the sign: 2 to the power 31 values on either side of zero, minus one at the top because zero takes a slot. Add 1 to 2,147,483,647 and the value wraps to -2,147,483,648. The type sets the edge, and crossing it is silent.
Why does 59 divided by 60 come out as 0? Both numbers are ints, so the division is integer division, and integer division drops the remainder. 59 divided by 60 is 0 with 59 left over, and the 0 is the answer the program keeps. Write one operand as a double and that division gives 0.9833333333. The values stayed put; the types decided the arithmetic.
Floats carry that lesson in finer print. 0.1 + 0.2 as a double came out 0.30000000000000004, and as a float 0.300000012. The number 0.1 has no exact binary form, so the machine stores the nearest value it can, and the tiny error shows in the sum. A single-precision float carries about 7 decimal digits; a double carries about 16. That gap is the reason money is stored as integer cents in production systems. Floats don’t hold money.
You can see the float error on your own machine in seconds. On Windows, open PowerShell and run python -c 'print(0.1 + 0.2)'. In a Mac or Linux terminal the command gives an identical answer, because the error lives in the binary format. The operating system has no say in it. Compare the printed digits with the ones above: they match to the last place.
Where a variable lives, and how long it lives?
Scope and lifetime answer two different questions, and mixing them up causes real confusion. Scope asks where the name is visible. Lifetime asks when the value exists. A name can be visible for a short stretch while its value outlives it, and a value can exist while no name in the current code can reach it.
Why does a variable inside a function forget its value? An automatic variable is created when its block starts running and destroyed when the block exits. The name and the storage both go. The next call starts fresh, with no memory of the last one.
A static variable inside one function behaves the other way. It is created once and keeps its value between calls. Two small counter functions, called three times apiece, printed these results: the static counter gave 1, 2, 3, and the automatic counter gave 1, 1, 1. Two functions, one shape, two lifetimes, and one keyword makes the difference.

My first attempt at that measurement printed 3, 2, 1, and for a moment the static counter looked broken. It was not broken; the three calls had run in reverse order before the results were printed. Separate statements gave the clean 1, 2, 3. The order a language evaluates arguments in is part of its rules, and it can surprise you.
Automatic variables live on the stack, and long-lived ones live on the heap. The two regions differ in who cleans them up, which is the stack vs heap memory distinction. Both regions sit in RAM, the working memory that holds a program’s values while it runs.
Constants: the variable that never changes
A constant is a named value the program refuses to change. You declare it with its value, and the compiler rejects any later assignment. The naming matches, the type matches, and the rules about change run opposite.
| Variable | Constant | |
|---|---|---|
| Value changes | Yes, by assignment | No, rejected at compile time |
| Declared with | A type and a name | A type, a name, and a value |
| Typical use | Input, counters, state that moves | Fixed numbers such as pi, a tax rate, a screen width |
| Reassignment | Replaces the stored value | Error, the program does not compile |
The compiler error is blunt. Declaring const int MAX_LIVES = 3 and then writing MAX_LIVES = 5 stops the build with this message:
error: assignment of read-only variable 'MAX_LIVES'
Constants earn their keep in three ways. Safety first: a typo cannot silently change a tax rate or a screen width, because the compiler stops the build. Clarity second: MAX_LIVES says more than a bare 3 scattered through the code. Substitution third: the compiler can replace the name with its value wherever it appears, so one change at the declaration reaches all of them.
One claim about constants needs correcting. A popular comparison page says constants improve efficiency, as if naming a value shrank its memory. It doesn’t. A constant is a name the compiler replaces; the value occupies its bytes, and the gain is safety and clarity, not smaller memory.
Python has no real constants. Programmers write names in all capitals by agreement, and nothing stops a later assignment. The protection there is convention and code review. The compiler offers none. On small embedded targets a constant can sit in read-only memory, where the hardware itself refuses a write, which is the strongest form of the idea.
The traps that catch beginners
Four traps catch most beginners, and all four show a visible symptom. The fix is one habit in all four cases: read the message the tool gives you, then look at the type, the name, or the lifetime.
- An uninitialized variable. A declared variable with no initial value holds whatever the memory already contained. This run printed 0 for one, and 0 is the most misleading number it could have printed, because it looks deliberate and means nothing. The compiler warned that the variable was used uninitialized. Another run can print anything. Initialise the variable and the trap disappears.
- Assignment where comparison belongs. Writing
if (age = 18)assigns 18 toageand tests the result, which is always true for a nonzero value. The compiler warns about it. The fix is the second equals sign:if (age == 18). - A typo that creates a new variable. In Python,
count = 5followed byconut = 6creates a second variable and leavescountat 5. The run printedcount is still: 5. No error appears, because Python treats any new name as a new variable. A linter or a typed language catches the slip; a plain script doesn’t. - Using a variable before declaring it. Printing
totalbefore any assignment stops the program withNameError: name 'total' is not defined. The name has no address yet, so there is nothing to read. Declare before use, and the error goes away.
Those traps leave evidence: a warning, an error, or a number that doesn’t match the one you expected. The evidence is the diagnosis. Beginners who read it fix the bug in minutes; beginners who ignore it rewrite working code.
Name the constant first
The next time you declare a value, ask first whether it ever changes. If the answer is no, make it a constant and give it a name that says what it means. If the answer is yes, choose the smallest type that holds the range you need. Initialise it on the line where you declare it, and keep its scope as narrow as the code allows.
That one habit removes the traps above at the source. Constants can’t be reassigned by a typo. A narrow scope can’t leak a stale value. An initialised variable holds no garbage. Start with the number that stays fixed in the program you are writing now, and give it a name.
Frequently asked questions
Can a variable hold two values at once?
No, a variable keeps a single value. Assigning a new value replaces the old bytes at the same address, so the old value is gone. If you need two values, you need two variables, or one variable that holds a collection.
Why do some languages not need a type when you declare a variable?
In Python and JavaScript the type belongs to the value, not the name, so the name can point at a number now and a string later. The compiler or interpreter checks the type when the value is used, not when the name is declared. The trade is flexibility now against errors the compiler could have caught earlier.
What happens to a variable when the program ends?
Its memory returns to the operating system, and the name and the value both disappear. Nothing about the variable survives into the next run, which is why a program that needs to remember must write its values to a file or a database before it exits.
Is a constant a variable with a fixed value?
Close, but the compiler treats them differently. A variable reserves storage that the program writes to; a constant is a name the compiler can replace with its value, and any assignment to it is an error. The distinction matters because the error is caught before the program runs.
How much memory does a variable use?
It depends on the type: 1 byte for a char, 4 for a C int, 8 for a double on this run’s compiler, and more for strings and collections that grow. The name itself costs nothing at run time, because the compiled program works with addresses.

Kaleem
Kaleem is a Computer Science graduate (Virtual University of Pakistan) and the founder and editor of Valley AI, where he publishes in-depth, tested guides on computer hardware, artificial intelligence, and how the internet works. Every guide is researched from primary sources, tested hands-on where possible, and updated when the facts change.