2

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 ?

1
  • "... as one can represent primitive objects too through reference variable..." Commented Jun 15, 2019 at 12:54

1 Answer 1

2

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."

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.