Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Variables declared outside of any function or block. They are accessible from any part of the program and persist throughout its entire execution.
int count = 0; // Global variable
void increment() {
count++;
}
int main() {
increment();
cout << count; // 1
}Global variables are automatically initialized to 0 (for numeric types) if not explicitly initialized.
Excessive use of global variables makes code hard to debug and maintain. Prefer local variables and parameters.