What is the difference between C and C++?
Simple meaning
C is procedural.
Open the full page for Why, Steps, Example and Key takeaway.
Panel-ready C++ interview set questions for freshers and experienced developers. Practice at Coding Cadre in Faridabad, or Online from Delhi NCR.
C is procedural.
Open the full page for Why, Steps, Example and Key takeaway.
Encapsulation, abstraction, inheritance, and polymorphism.
Open the full page for Why, Steps, Example and Key takeaway.
Stack holds locals and is freed when the function returns
Open the full page for Why, Steps, Example and Key takeaway.
A pointer can be null and can be reseated.
Open the full page for Why, Steps, Example and Key takeaway.
New allocates on the heap and calls constructors.
Open the full page for Why, Steps, Example and Key takeaway.
A constructor sets up the object when it is created.
Open the full page for Why, Steps, Example and Key takeaway.
The only language difference is default access: public for struct, private for class.
Open the full page for Why, Steps, Example and Key takeaway.
Overloading is same name, different parameters, resolved at compile time.
Open the full page for Why, Steps, Example and Key takeaway.
If the destructor is not virtual, only the base destructor runs and the derived cleanup is skipped.
Open the full page for Why, Steps, Example and Key takeaway.
It enables dynamic dispatch through a vtable so the derived method runs on a base pointer.
Open the full page for Why, Steps, Example and Key takeaway.
Ifndef define endif, or pragma once, stops a header from being included twice in one translation unit.
Open the full page for Why, Steps, Example and Key takeaway.
It groups names to avoid clashes, like std.
Open the full page for Why, Steps, Example and Key takeaway.
A const member function promises not to mutate the object, so it can be called on a const instance.
Open the full page for Why, Steps, Example and Key takeaway.
Vector is a dynamic array: contiguous, O(1) index, amortized push_back.
Open the full page for Why, Steps, Example and Key takeaway.
List is a doubly linked list: stable iterators on insert, but poor cache use and no random access.
Open the full page for Why, Steps, Example and Key takeaway.
By value copies
Open the full page for Why, Steps, Example and Key takeaway.
A class with at least one pure virtual function, written as virtual f() = 0.
Open the full page for Why, Steps, Example and Key takeaway.
The standard gives no requirements, so the compiler may do anything: use-after-free, signed overflow, out-of-bounds.
Open the full page for Why, Steps, Example and Key takeaway.
If I write a destructor, copy constructor, or copy assignment, I likely need all three.
Open the full page for Why, Steps, Example and Key takeaway.
Resource acquisition is initialization: the constructor takes the resource, the destructor releases it.
Open the full page for Why, Steps, Example and Key takeaway.