When we write int a;, it doesn’t mean that we are creating an object of class int.
- What does it mean?
- What is the type of the datatype int in C and C++?
- Which header file shows what it is?
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.
int a;does indeed create an object in C++. It’s an object of typeintwith indeterminate value if it has automatic storage duration; or with value0, if it has static storage duration. But there is no “classint” becauseintis not a class type.intis a:Seems like you got a bit confused in your previous question 🙂
In
int x = 12;, you are creating an object of typeintthat is namedxand has value 12.The idea of object in C++ is not the same as in most other languages, and most certainly is not the same as is commonly used in object-oriented programming circles. An object in C++ is a region of storage.
If something has a type, it’s either an object, a reference, or a function.
The language simply requires that the type
inthas to exist and have certain characteristics (like being integral and having a sign). All compilers I know of simply treat all the builtin types specially and that’s why you won’t find a definition for them in the standard library headers. In fact, they can’t provide a definition for them in any header using C++, because the language doesn’t provide any means of defining fundamental types. They could only either:The builtin types are effectively magic.