By definition, if something is not initialized, it does not have a defined value. If it does have a defined value, it is initialized.
From cppreference:
The value in an uninitialized variable can be anything – it is
unpredictable, and may be different every time the program is run.
Reading the value of an uninitialized variable is undefined behaviour
– which is always a bad idea. It has to be initialized with a value
before you can use it.
Also from cppreference about implicit initialization:
If an initializer is not provided:
- objects with automatic storage duration are initialized to
indeterminate values (which may be trap representations)
- objects with
static and thread-local storage duration are zero-initialized
So for example, int a;
will be zero-initialized if declared in e.g. global scope, as a static class variable, as a thread_local
variable, etc. In other cases, it will be uninitialized.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…