C and C + + Introduction to the difference

Source: Internet
Author: User
Tags command line data structures header

1. Although C + + is mainly a new language developed on the basis of C, she is not a substitute for C, it is not an upgrade of C, C + + and C are brotherly relations. No one is more advanced than the saying that the more important point is C and C + + the respective standards committees are independent, the newest C + + standard is c++98, and the newest standard is C99. So there is no first to learn C C + +, also no longer (note this "no longer") has C + + grammar is a superset of the word.

2. C++/cli and C # are Microsoft's, and they have nothing to do with C and C + +, although some of the syntax is similar. But which two languages are not similar? These 26 letters are ABC.

3. Do not use the old compilers such as TC/TC++/BC/CB to learn C + +, because they are too old to support the new C + + standard. Do not use cbx/vc++6.0/vc2005, etc. to support the C + + standard not good compiler, although these compilers are suitable for work, but not suitable for learning, because they have a lot of syntax traps. Remember that the only compiler for learning is GCC/MINGW. [Antigloss Note: Dev-c++ uses the compiler is GCC & g++]

4. Do not use "" instead of <> to include the system header file, although some compilers allow you to do so, but it does not conform to C + + standard.

Example of an error: #include "stdio.h", #include "iostream". [Antigloss Note:,<> used to include standard header files and system header files, "" is used to include custom header files. The standard does not seem to specify that "" contains standard header files and system headers. Using the Include standard header file or system header file can only be said to be a bad style. ]

5. Do not define the return type of the main function as void, although some compilers allow you to do so, but it does not conform to the C + + standard. Do not omit the int return type of the function and ask the compiler to give at least one warning in C + +. Example of an error: void Main () {},main () {} [Antigloss Note: Both C99 and c++98 require the compiler to issue at least one warning for omitting int] If you do not need to get arguments from the command line, use int main (void); Main (int argc, char *argv[]).

6. Do not put the VC + + #include "stdafx.h" posted out, it is precompiled header file. Do not put the chef in the tray as you serve the dishes.

7. [C + +] do not #include <iostream.h>, do not #include <string.h>, because they have been explicitly abandoned by the C + + standard, please change to #include <iostream> and #include <cstring> the rules are:

A. If the header file is old C + + specific, then remove it. h suffix, and put in the STD name space,

For example, iostream.h into iostream.

B. If the header file is C, then remove it. h suffix, add a c prefix, such as string.h

into cstring;stdio.h into Cstdio, and so on.

BTW: Do not confuse string, CString, string.h three header files

Btw:windows.h is not a standard file for C/s + +, so it is named C + + regardless.

8. Do not write char* p = "XXX" Such statements, to write a const char* p = "XXX", the compiler makes the former through the compilation is to be compatible with the previous large number of old code. [Antigloss Note: This passage is correct for C + +. However, the current C99 standard does not seem to define "XXX" must be a constant. ]

Btw:const type* p and TYPE const* p are the same, with different styles.

The Btw:c language also has a const keyword.

9. Do not include multiple ++/--of a variable in the same statement, because their parsing is not specified in the C + + standard, depending entirely on the individual behavior of the compiler.

C/s + + is a platform-independent language, so system-related process/gui are not in the standard C + + library. For example, Graphics.h and windows.h are provided by a compiler, not by C + +.

C + + is only a language, but also a platform-independent language. Some people on the forum even think that C is dos,c++ is windows, then what is Linux?

12.[c++] Object-oriented was once the primary goal of designing C with Class (the predecessor of C. C + +), but C + + is not, C + + is a multiple-model language. The main support process call, object-based, object-oriented, generic programming four kinds of programming examples. Of course also support functional, generative,metaprogramming and other models.

13. A jurist is not a writer, so when you learn a computer language, you also need to learn data structures and algorithms, as well as the use of tools and Platform APIs.

C + + is a common language, so the syntax is complex, and you should cut into a set of grammars that fit your own, such as better C and ADT.

C + + is a common language, so it contains only generic libraries, and you should enrich the libraries that you need, such as the Automotive Industry Association has its own c/s + + function/class/Template library.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.