I am a beginner to c++. I read it on internet reference is the object. My question regarding this, as one can represent primitives too through reference variable Ex- int a=3;int &s=a;, then where does the contradiction lie ?
- "... as one can represent primitive objects too through reference variable..."Eljay– Eljay2019-06-15 12:54:59 +00:00Commented Jun 15, 2019 at 12:54
Add a comment |
1 Answer
In C++, "object" does not only refer to class instances. An int variable is also called an object. It's an object of type int.
See: https://en.cppreference.com/w/cpp/language/object
An object, in C++, is a region of storage that has a size, an alignment, a storage duration, a lifetime, a type, a value, and (optionally) a name.
An int variable therefore is an object. Yes, int is a primitive type, but variables of primitive types are also called "objects."