Although C + + is designed to be backward compatible with C, many C programs may produce compiler errors when compiled with C + + compiler. Here are some of them.
1）In C + +, calling functions is a compiler error before declaring functions. But in C, it compiles
2）In C + +, it is a compiler error to make the common pointer point to const variable, but it is allowed in C.
3）In C language, void pointer can be directly assigned to other pointers, such as int *, char *. But in C + +, you must explicitly type the void pointer.
We’ll notice this when we use malloc(). The return type of malloc() is void *. In C + +, we must explicitly convert the return value type of malloc() to an appropriate type, such as “int * P = (int *) malloc (sizeof (int))”. In C, type conversion is not required.
4）The following programs can be compiled and run normally in C, but they fail to compile in C + +. The const variable in C + + must be initialized, but it is not necessary in C. Thank pravasi meet for making this point.
Line 4 [error] uninitialized const’a ‘[- fpermissive]
5）That’s the worst answer, but it’s still valid. We can use one of the C + + specific keywords as the variable name. The program will not be compiled in C + +, but will be compiled in C.
Similarly, we can use other keywords, such as delete, explicit, class, etc.
6）C + + does more strict type checking than C. For example, the following program is compiled in C, but not in C + +. In C + +, we get compiler error “invalid conversion from ‘Int’ to ‘char *”. Thank pravasi meet for adding this.
7）C + + requires the main return ‘Int’ type
Hope to help you! More programming knowledge, will continue to share Oh~
In addition, if you want to better improve your programming ability, learn C language c + + programming! Overtaking on the curve, one step faster! I may be able to help you here~
C language c + + programming learning circle,QQ group 1090842465【Click to enterWeChat official account: C language programming learning base
Share (source code, project video, project notes, basic introductory course)
Welcome to change and learn programming partners, use more information to learn and grow faster than their own thinking Oh!
Programming learning book sharing:
Programming learning video sharing: