C vs C++

Unit 1 Β· Topic 1.5⏱ 8 min read❓ 5 MCQs

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

  1. List 3 differences C vs C++.
  2. What are references?
  3. new vs malloc?
  4. cin vs scanf?

Long Questions

  1. Compare C and C++ features.
  2. 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.