0

What's the difference bewteen an obejct and a variable?

14th Feb 2019, 5:11 AM
Manav Malhotra
Manav Malhotra - avatar
2 Answers
+ 9
A variable is a named memory location that is used to store modifiable data, for example: int x = 42; Here `x` is a variable. later on, as necessary, we can change value stored in variable `x`. An object is an instance of a class, a real representation of the class that defines its characteristics and behaviour. For example: class Cat { // member definition ... }; int main() { Cat Dora; } <Dora> is a variable which stores an object created (or instantiated) from `Cat` class. Conclusion: A variable can store intrinsic (primitive) types, or objects. Hth, cmiiw
14th Feb 2019, 5:43 AM
Ipang
+ 1
Well if you are thinking a variable as the storage space for some data type like int, float, char etc you will notice that they are system defined variables as in case of objects they are user defined variables
14th Feb 2019, 5:43 AM
Sahil Bhakat
Sahil Bhakat - avatar