What is object in C language?

Answer:
C is procedural programming language and does not have any object orientated paradigm.

But there is C++ programming language that is C Object-Orientated approach and one of the most popular programming language (rapidly going down).

C++ brought some features to C programming languages. And one of them is support for classes with fours main OO (Object-Orientated) features: encapsulation, abstraction, inheritance and polymorphism.

Object is an instance of the class, which is created at run-time.

Class is like a template for Object. It tells what kind of data inside it should have and what kind of operations are possible with it (abstraction).

Here is example of the Class:

class Point {
public:
Point();
Point(int x, int y);
~Point();
void setPoint(int x, int y);
int getX();
int getY();
private:
int x;
int y;
};

Point::Point() : x(0), y(0) {
}

Point::Point(int x, int y) {
this->setPoint(x, y);
}

Point::~Point() { }

void Point::setPoint(int x, int y) {
this->x = x;
this->y = y;
}

int Point::getX() {
return this->x;
}

int Point::getY() {
return this->y;
}


Here is example of small program that creates two objects and manipulates them:

#include

using namespace std;

int main() {
Point *a = new Point(1, 2); // Object a
Point *b = new Point(3, 4); // Object b
cout << "a.X = " << a->getX() << "; a.Y = " << a->getY() << endl;
cout << "b.X = " << b->getX() << "; b.Y = " << b->getY() << endl;
delete a;
delete b;
return 0;
}
First answer by David.lt. Last edit by David.lt. Contributor trust: 23 [recommend contributor recommended]. Question popularity: 2 [recommend question].