Object-oriented programming in ANSI-C is a disciplined approach that implements information hiding, inheritance, and polymorphism by leveraging standard C features like structures and function pointers
It utilizes abstract data types and dynamic linkage to separate implementation from usage, enabling robust code reuse and manageable system decomposition within the confines of plain C
Basic data types provided by the programming language, such as integers, floats, and characters, along with built-in operations like addition, subtraction, and multiplication.
A data type defined by a set of values and a set of operations, where the implementation details are hidden, and only the interface (operations) is exposed to the user.
Example: Javascript (push, pop, shift, unshift)
We build a modular Point entity from scratch:
- The Interface (
Point.h): Defining opaque pointers and exposing only necessary operations (new,move,print,delete). - The Implementation (
Point.c): Handling the actual struct definition and memory management usingmallocandfree. - The Application (
main.c): Consuming the ADT to manipulate data without direct access to the internal structure.
cd AbstractDataTypes/points/
gcc Point.c main.c -o ProgramFile
./ProgramFile