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
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.