StudyGraph
Procedural Programming with C++ Explainer

Why Your Counter Starts at 32767

In C++, a local int you never set can hold any random number.

Lesson notes

Key points

Definitions

Uninitialized variable
A variable declared without a value; reading it gives whatever bits were left in that memory.

Takeaway: Initialize every local variable when you declare it.

Quick check: What does a local int x; hold before assignment?
  1. Always 0
  2. An unpredictable value
  3. A compile error

DeclarationUndefined behaviourZero-initializationInitialize always

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