The C/C++ incompatibilities that cause most real problems are not subtle. Most are easily caught by compilers.
This section gives examples of C code that is not C++ :
1) In C, functions can be defined using a syntax that optionally specifies argument types after the list of arguments:
Output: 8 9
Error in C++ :- a and b was not declared in this scope
2) In C and in pre-standard versions of C++, the type specifier defaults to int.
Error in C++ :- a does not name a type
3) In C, a global data object may be declared several times without using the extern specifier. As long as at most one such declaration provides an initializer, the object is considered defined only once.
Error in C++ :- Redefinition of int a
4) In C, a void* may be used as the right-hand operand of an assignment to or initialization of a variable of any pointer type.
Error in C++ :- Invalid conversion of void* to int*
5) In C, an array can be initialized by an initializer that has more elements than the array requires.
Error in C++ :- Initializer-string for array of chars is too long
6) In C, a function declared without specifying any argument types can take any number of arguments of any type at all. Click here to know more about this.
Error in C++ :- Too many arguments to function 'void fun()'
- Is it fine to write “void main()” or “main()” in C/C++?
- Difference between “int main()” and “int main(void)” in C/C++?
- Output of C++ programs | Set 24 (C++ vs C)
This article is contributed by Sakshi Tiwari. If you like GeeksforGeeks (We know you do!) and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- How to implement our own Vector Class in C++?
- Web Programming in C++
- C++ Program to print an Array using Recursion
- Storage Classes in C++ with Examples
- fill_n() function in C++ STL with examples
- fill() function in C++ STL with examples
- How to erase an element from a vector using erase() and reverse_iterator?
- iomanip setbase() function in C++ with Examples
- iomanip setpricision() function in C++ with Examples
- iomanip setiosflags() function in C++ with Examples
- iomanip setfill() function in C++ with Examples
- Manipulators in C++ with Examples
- iomanip setw() function in C++ with Examples
- iomanip resetiosflags() function in C++ with Examples