Skip to main content

C versus C++ and C++ features

Short answer

C is procedural; C++ adds object-oriented capabilities. Key C++ features: classes (class Box { int side; }), overloading (int add(...), float add(...)), templates (template<class T> T max(T,T)), inheritance, exceptions, references, and new/delete for dynamic memory.

Compare C and C++. Write down different features of C++ with example for each.

Comparison of C and C++

PointCC++
ParadigmProceduralProcedural and object oriented
Basic unitFunctionClass / object
Data hidingNot possiblePossible (private, protected)
OverloadingNot supportedFunction and operator overloading
Memorymalloc() / free()new / delete
I/Oprintf() / scanf()cout / cin
ReferencesNo (pointers only)Reference variables
Inheritance and polymorphismNoYes
Exceptions, templates, namespacesNoYes
Inline functionsNot in original CSupported

Features of C++ with examples

  1. Classes and objects
class Box { public: int side; };
Box b; b.side = 5;
  1. Encapsulation and data hiding
class A { private: int x; public: void set(int v) { x = v; } };
  1. Inheritance
class Student : public Person { };
  1. Function overloading
int add(int a, int b);  float add(float a, float b);
  1. Operator overloading
Complex operator+(Complex c);
  1. Polymorphism by virtual functions
class Shape { public: virtual void draw(); };
  1. Templates
template <class T> T maxOf(T a, T b) { return a > b ? a : b; }
  1. Exception handling
try { if (d == 0) throw 0; } catch (int e) { cout << "Divide by zero"; }
  1. Reference variables and inline functions
void swap(int &a, int &b);   inline int sq(int x) { return x * x; }
  1. Dynamic memory
int *p = new int[10];  delete[] p;

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Programming chapter 2 questions →