开发者

Visual C++ 2005 - are local int and double variables initialized to 0 by default or not?

开发者 https://www.devze.com 2023-02-22 01:54 出处:网络
My C++ got a bit rusty, so a quic开发者_如何学Gok question in Visual C++ 2005 - are local (to function) int and double variables initialized to 0 by default or not?

My C++ got a bit rusty, so a quic开发者_如何学Gok question in Visual C++ 2005 - are local (to function) int and double variables initialized to 0 by default or not?

Is the right that in the following code:

void Foo()
{
int a, b, c = 0;
double d, e, f = 0.0;
}

c and f are initialized to 0 and 0.0 respectively while b, c, d and e are uninitialized and will likely to contain some garbage when compiled in a release mode with all the optimizations are on?


They are not initialized by default. a,b,d and e will be uninitialized.


automatic local variables are not initialized unless they are explicitly initialized in your code, or are of type with default constructor

cheers & hth.,


they contain some garbage values unless initialized by some value. Not matter they are local or global.

0

精彩评论

暂无评论...
验证码 换一张
取 消