Looking into languages such as Java & C# use of uninitialized local variable is compile time error. Then why C & C++ allows uninitialized local variables? What is the reason that these languages allows this? I think many of the bad problems can't arise or can be prevented if these 2 languages forces programmer to mandatory initialize local variables including pointers & it also makes language more secure. Doesn't it?
The C language is well known for producing very fast and efficient code.
With that in mind, it makes sense for the language not to automatically initialize all variables. With languages that automatically initialize variables, if you later initialize them in code, they actually get initialized twice, which is less efficient and serves no purpose.
You are correct, C is an advanced language and it requires more care by experienced developers to ensure problems are not introduced by forgetting to initialize variables, or forgetting to do other things that are not automatic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With