What is the difference between C and C++?

PointCC++
StyleProceduralProcedural, object oriented, generic
ClassesNoYes
OverloadingNoYes
ReferencesNoYes
Templates, exceptionsNoYes
Strings and containerschar arrays, own codestd::string, STL
Memorymalloc and freenew, delete, smart pointers
I/Oprintf, scanfcout, cin, print

This C code is not valid C++, because C++ does not convert void* automatically:

#include <stdlib.h>

int main() {
    int* p = malloc(sizeof(int));
    free(p);
}
Output

Bad.cpp: In function 'int main()':
Bad.cpp:4:20: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
4 | int* p = malloc(sizeof(int));
| ~~~~~~^~~~~~~~~~~~~
| |
| void*

See C++ vs C.


Learn more about the similar topics:
Tutorials
C++ Introduction
C++ History and Versions
C++ Features
C++ vs C
C++ Installation and Setup
Your First C++ Program: Hello World
C++ Syntax
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is C++?
What are the main features of C++?
What is the difference between C and C++?
What are the different versions (standards) of C++?
What is the use of #include in C++?
What is the difference between cout and printf in C++?
What is the difference between endl and \n in C++?