c2cedge
C, Java & Python · A — Foundations

Data Types, Variables & Memory

Static or dynamic typing, value or reference, stack or heap — the model of how each language stores data drives a huge share of interview questions.

Test weight: Very highSkill: Mental model of memoryDifficulty: Medium

How a language treats variables and memory underlies endless interview questions. The key axes: static vs dynamic typing (must you declare a type?), primitive vs object (is a value stored directly or via a reference?), and where data lives (stack vs heap). C and Java are statically typed; Python is dynamic. Java splits primitives from objects; in Python, everything is an object.

Typing and what a variable holds

Static typing (C, Java): a variable's type is fixed at compile time and declared. Dynamic typing (Python): a name is just a label bound to an object, and can be rebound to a different type. In C/Java, primitives (int, char) hold the value directly; objects hold a reference. In Python, a variable is always a reference to an object.

Typing across the three

CJavaPython
Declare type?yes (int x;)yes (int x;)no (x = 5)
Checked whencompile timecompile timeruntime
int sizeplatform (often 32-bit)fixed 32-bitarbitrary precision
Everything an object?nono (primitives aren't)yes
Declaring a variable in each
/* C */    int x = 5;        // fixed type, value stored directly
// Java     int x = 5;        // primitive; Integer x = 5; is an object
# Python    x = 5             # name bound to an int object; x = 'hi' is fine later
⚡ The edge
  • In Python a variable is a name bound to an object, not a box holding a value. Assignment rebinds the name; it doesn't copy. That's why two names can refer to the same list and both 'see' a change.
  • C and Java integers have a fixed size and can overflow; a 32-bit int wraps around past ~2.1 billion. Python integers have arbitrary precision and never overflow — they grow as needed.
Worked example
What is the difference between a primitive and an object in Java?
  1. A primitive (int, char, boolean, double...) stores its value directly and isn't a class instance.
  2. An object (String, Integer, any class) is accessed via a reference to memory on the heap.
  3. Java auto-converts between them where needed — autoboxing (int→Integer) and unboxing (Integer→int).
Worked example
Why can a C int overflow but a Python int cannot?
  1. A C int has a fixed width (commonly 32 bits), so it can only hold a limited range of values.
  2. Exceeding that range wraps around (overflow), often to a negative number.
  3. Python integers are arbitrary-precision — the interpreter grows them as needed — so they never overflow.
⚠ Watch out
  • Static vs dynamic typing: C/Java check types at compile time; Python at runtime — a type error in Python only appears when that line runs.
  • Fixed-size integer overflow in C/Java is a classic bug; Python is immune.
  • In Python, assignment binds a name to an object and doesn't copy — crucial for mutability questions (next chapters).
Practice this — take a timed mock →
1,300+ questions, scored, with a weak-area report.
Know who's ready. Not who finished.
HomeLibraryPrivacyTerms