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 email@example.com. 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.
- cin get() in C++ with Examples
- Difference between Increment and Decrement Operators
- Map of Vectors in C++ STL with Examples
- Problem in comparing Floating point numbers and how to compare them correctly?
- exit(0) vs exit(1) in C/C++ with Examples
- Predefined Macros in C with Examples
- How to create GUI in C programming using GTK Toolkit
- C++ program to print all Even and Odd numbers from 1 to N
- Reverse the content of a file and store it in another
- ctype.h(<cctype>) library in C/C++ with Examples
- Minimum cells to be flipped to get a 2*2 submatrix with equal elements
- Nested Loops in C++ with Examples
- Slack Bytes in Structures : Explained with Example
- _Find_first() function in C++ bitset with Examples