Important Notice:

Programming Language C/C++ — ADCA Notes

Programming Language C/C++ — ADCA Notes

17 views 1 min read

Programming with C & C++

C is a procedural programming language. C++ is an extension of C that supports Object-Oriented Programming (OOP).

C Program Structure #include <stdio.h>

int main() { printf("Hello, World!\n"); return 0; } Data Types in C TypeSizeExample int4 bytesint a = 5; float4 bytesfloat b = 3.14; double8 bytesdouble c = 3.14159; char1 bytechar d = 'A'; Control Statements // if-else if (a > 0) { printf("Positive"); } else { printf("Negative"); }

// for loop for (int i = 0; i < 5; i++) { printf("%d\n", i); }

// while loop while (a > 0) { a--; } Functions in C int add(int x, int y) { return x + y; } int main() { int result = add(3, 4); // result = 7 return 0; } C++ & OOP Concepts

  • Class: Blueprint for objects
  • Object: Instance of a class
  • Encapsulation: Wrapping data & functions together
  • Inheritance: Derived class inherits from base class
  • Polymorphism: Same function, different behavior
  • Abstraction: Hiding internal details

class Animal { public: string name; void speak() { cout << "Sound!" << endl; } };

class Dog : public Animal { public: void speak() { cout << "Woof!" << endl; } };