Does int a = int(); necessarily give me a zero?
How about if int is replaced by char, double, bool or pointer type?
Where is this specified in the language standard, please?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, the standard guarantees that it gives you zero.
This is known as Value Initialization. For the type
int, Value Initialization basically ends up being an Zero Initialization.The rules are clearly specified in the standard in section 8.5.
I will quote the relevant ones to the Q here:
C++03: 8.5 Initializers
Para 7:
Value Initialization & Zero Initialization are defined in 8.5 Para 5 as:
Note: The bold texts are emphasized by me.