Procedural Programming with C++
Guess first
What does int age; print? Guess first
Most students get this wrong: what does an uninitialised int print?
Quick check · tap an answer to continue
Lesson notes
Declare and initialise variables of fundamental types and explain how type sets size and range
Key points
- Inside a function, int age; reserves memory but sets no value, so printing it gives indeterminate garbage, not zero.
- The data type sets the size, so sizeof(int) is usually 4 bytes while sizeof(double) is usually 8 bytes.
Takeaway: An uninitialised local int is indeterminate, never guaranteed zero.
Quick check: In main(), int age; then cout << age; What prints?
- 0
- A compile error
- Unpredictable garbage
Local variables are not zeroed: always initialise, e.g. int age = 20;
data typeinitialisationscopeIndeterminate valueData type
Lessons like this, for your syllabus.
Short narrated study videos written for your course, level and exam. Free to start.
Get lessons for your own syllabus