Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello bosses

is OBJECT or INSTANT in OOP is as same as VARIABLE IN C programming?
Posted
Comments
Sergey Alexandrovich Kryukov 14-Feb-14 21:33pm    
The question simply makes no sense. Nothing is "the same". "Instance", not "instance". No, not the same. C also has objects, in wider sense of the word, and, in C along, "object" and "variable" are not the same.
The only useful answer would be a big lecture on OOP, and, most likely, you would need a big lecture on more basic programming.
But this is not the right place for such things. You should better learn some basics and come back with more adequate questions. This post is almost the same as asking "what is programming?". Can be somehow answered, but asking this way is not productive enough.
—SA

1 solution

No, not the same. In essence, the answer can be found in my comment to the question.

I think it would be enough if I give you some hint withing the scope of C only. You are not yet ready for OOP and need to understand some more fundamental notions before jumping to OOP. Even in C, object and variable is not the same. Object is something you work with and something which takes place in memory during runtime. In programming, there is such a fundamental thing as pointer. Physically, pointer is represented as some machine address (in one or another address space; it depends on the platform), and, therefore, is itself and object. And the address can point to some memory location. And here there can be one more object, the object pointed by the pointer.

Now, a pointer may or may not have the name in your source code. And this would be the variable name. Variables per se do not exist during runtime; there are the artifact of your source code. Physically, this is also an address of some object, on stack, on heap or in the memory reserved for static objects (some developers know the notion of "data segment", but this also depends on the platform). Object may or may not have the name. Consider this:
C++
int a = 13; // integer object, its name is "a" (will not exist during runtime)
int b = 14;
int * c = &a; // initialize pointer c as address of a
// now pointer c points to location of memory containing 13
c = &b; // and now -- different location containing 14

You can pass the pointer c to some context where a and b do not exist, so you can have the pointer which is itself pointed by some name ("c"), but the integer object itself have no name. One obvious way to do that is to allocate memory on the heap. So, you can have an object without a variable. For example a linked list can have N objects on certain type, but only head object has a pointer pointing to it. Learn linked lists; without them, you hardly can understand programming.

Now, OOP object are similar to the objects of struct types which you could have in C. But, in addition to that, you can have a lot more. The root of OOP is virtual methods (and hence virtual tables), overriding (dynamic dispatch of calls) and hence, late binding and polymorphism. To get to the point you can understand all that, you really need to understand how objects and variables work in some low-level language like C.

—SA
 
Share this answer
 
Comments
Member 10583150 14-Feb-14 22:14pm    
amazing reply. though it did not answer what i am looking for but i have learnt a lot and opened lots of door for me towards my target. thanks a lot.
Sergey Alexandrovich Kryukov 14-Feb-14 23:55pm    
It did not answer it, because I think it makes no sense at the moment. I tried to explain what you need to understand first and give you the idea of your possible further steps. If you can clarify your questions more, based on what I already told you, it would be more useful.
So, I would recommend you to accept this answer formally (green "Accept" button) and ask some follow-up questions, if you got any. You can wait for other answers, nevertheless.
—SA
Peter Leow 15-Feb-14 0:52am    
Excellent, high 5!
Sergey Alexandrovich Kryukov 15-Feb-14 6:08am    
Thank you, Peter.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900