Given the following declaration:
double x;
What is the value of x?
Is my answer correct?
The value of x is: plus or minus 10 to 308th (limited to ~12 significant digits)
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.
No, your answer is not correct. What thought process led you to that answer? Where might you have gone wrong?
Given the proliferation of “answers” on this question, I’m just going to come out and state it. The answer is that the value of x is undefined. It’s an uninitialized value. If you try to read the value, in practice you’ll get garbage (i.e. you’ll get whatever bit pattern was in that memory location, reinterpreted as a
double). But it’s not as simple as that. Since the value is undefined, the optimization pass of the compiler is actually free to make choices based on the undefined value that it could not have made if the variable had any defined value. Any attempts to use an uninitialized variable can produce unexpected results, and is certainly a programming error.There is one caveat, as I alluded to in my comment. If this declaration happens at the top level (or is modified with the
statickeyword) then the value becomes simply0.0.