C vs C++
Last Update Unknown
Headers
C:
C++:
But make sure to use .h for headers you make
The letter c tends to go in front of header files from regular C i.e. <cstring> for <string.h>Click here for more info on important C++ headers.
Namespaces
scope that can span across multiple files
C++ uses namespace std to deal with strings and string functions!
Stream in / out
C:
C++:
cout is the equivalent in c++ of printf
cin is the equivalent of scanf or fgets
cout and cin are much more versatile than their C equivalents!
Strings
C:
C doesn't have a proper string type and has limited functionality only acting as an extended char.
C++:
C++ brings an actual string type and many useful functions. Remember to include using namespace
std too for a lot of string functions!
Booleans
C:
C++:
Booleans are built in to c++ and can just be defined using bool
Booleans have the value:
- true (1)
- false (0)
Functions
C:
C must have void specified as an argument whereas C++ does not require it.
C++:
Enum definition
C:
C++:
Struct definition
C++:
The typedef keyword is not required for C++
Struct - Enum member scope
C:
C++:
Construction
C:
C++:
- No named members in construction
- Can still use assignment-style