You are here:

C++/About oops


Dear sir,
    Thanks for answering my previous questions.I have again some questions.

1) what is the difference between object oriented programming & object based programming.
2)what is NULL macro.
3)What is NULL pointer.

 Please clarify my doubts.

Hello again satish, thank you for the question.

For your first question, again, I'm not sure what you mean when you say object based programming. I've never heard that term before. I'm going to assume you mean structured programming a la C.

OOP should have a modular design implementing each class as a seperate piece of a larger entity. Lets say you wanted to make a new game. You might create a class called object which is pure virtual, ie you can't create any objects from it. The Object class would contain all the things common to an object in the game. Like, a world position, a bounding volume for collision testing, a current motion vector, and so on. And you could inherit classes from this class, like an animal, a player, and a rock. Each of those derived classes would need all those things we have determined to be common to an object, but also are independently modular in design.

Structured programming isn't concerned with invoking objects. The code is still typically modular, but variables can not have member functions. Functions have to be robust enough to be able to apply the same algorithm to all variables of the same type. There is also no concept of data encapsulation with the private declaration of variables. A C-style function will take in an object that the function will applied to typically as its first parameter. Here is a sample structure function that manipulates the objects integer variable:

void Calc(Object *pObj, const int num)
pObj->x *= num;

The OOP equivalent would be:

void Calc(const int num)
x *= num;

Assuming that the function is a member function or a friend of the class.

I hope that was what was meant by object based programming. If not, I'll be happy to try and explain again when provided with a definition.

For questions 2 and 3, NULL is #defined as 0 in the file windows.h. Whereas it could be confused as a macro because macros are typically created with a #define, it is just another way to create a const int that is equal to 0. A NULL pointer points to the invalid memory address(0x00000000). NULL pointers will crash your program every time. It is proper code stadard to initialize your pointers to NULL when done with them so you don't have the aggravating undefined pointers in your program. Here is a sample:

int *pInt = new int;

(*pInt) = 5;

cout << (*pInt) << '\n';

delete pInt;

pInt = NULL;

That way pInt has been properly deallocated and shut down. This becomes critical when you start dealing with advanced pointer topics like Linked Lists. Setting the pointer to NULL also looks better than setting it to 0 to me for some reason. If you have any other questions please don't hesistate to ask again.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 All rights reserved.