Does int vars automatically get assigned (0) in Modern C++?

Hello,

Title says it all; I am wondering if integers and unsigned integers automatically assigned to zero (0) upon declaration like so:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

bool randomFunction() {

int i;

if (i == 0) {

return true; //Will most modern compilers return true here?

}

else {

return false;

}

}


I am just curious as I have always initialized my ints/unsigned ints variables. Would save me a lot of typing if I didn't have to do this all of the time.

I know that floats and doubles you still have to initialize.

Thank you.
No, they are not. It would mean additional work which is probably unneeded = loss of speed which is directly contradicts C++ pronciple do not pay for what you do not use
Last edited on
Still, typing int i {}; is trivial.
Last edited on
Some compilers do that in some types of build, but the C++ standard says nothing about initialising them to zero. So, the general answer is: No.
OK, thank you for the fast replies!
Topic archived. No new replies allowed.