C vs C++
Introduction
C++ extends C with OOP features: classes, objects, inheritance, polymorphism, encapsulation, plus references, function overloading, and new/delete.
Definition
C: procedural. C++: multi-paradigm (procedural + OOP).
C
- Procedural
- scanf/printf
- malloc/free
- No classes
C++
- OOP + procedural
- cin/cout
- new/delete
- Classes/objects
Code Example
// C++ I/O and class
#include <iostream>
using namespace std;
class A{ public: void hi(){cout<<"hi\\n";} };
int main(){ A a; a.hi(); return 0; }Important Questions
Short Questions
- List 3 differences C vs C++.
- What are references?
- new vs malloc?
- cin vs scanf?
Long Questions
- Compare C and C++ features.
- Explain references and overloading.
MCQ Practice
1. C++ supports:
- OOP
- Only procedural
- Only functional
- None
Answer: OOP.
2. Memory allocation in C++ uses:
- new/delete
- malloc/free only
- alloc only
- none
Answer: new/delete.
3. Function overloading is:
- C++ feature
- C feature
- Both
- Neither
Answer: C++ feature.
4. References are available in:
- C++
- C
- Both
- Neither
Answer: C++.
5. I/O in C++ uses:
- cin/cout
- scanf/printf only
- read/write only
- none
Answer: cin/cout.
Quick Revision
- C++ = C + OOP.
- new/delete, references, overloading, classes.