Chapter one Preliminaries
1, C ++ historical origins
Since the C language has many advantages, such as simple and flexible language; rich set of operators and data types; having the structure of control statements; high efficiency of program execution; also has other advantages of the high-level language and assembly language. Compared with other high-level language, C language has the advantage of direct access to physical addresses, and assembly language also has good readability and portability compared. Therefore, C language has been very widely used. But since C is a process-oriented (i.e., oriented structure) programming language, object-oriented development can not meet the needs of the software. To support object-oriented programming, in 1980, created by Bjarne Stroustrup at Bell Labs in the C ++ programming language, C ++ is an important goal of object-oriented programming, so the introduction of a mechanism like in C ++. So in 1983 officially named C ++ (C Plus Plus).
2, C ++ features
The main features of the C ++ language is manifested in two aspects, one is fully compatible with the C language, and second, to support object-oriented programming approach.
- Fully compatible with C language: C ++ uphold the advantages of the C language, most of the C code slightly modified with or without modifications can debug and run in C ++ integrated environment. This is the inheritance and development of the software currently in widespread use is very important, it can save a lot of manpower and material resources.
- Support for object-oriented programming: C ++ is an object-oriented programming language. It makes the program the independence of each module stronger, readability and portability of a stronger program, the program code structure is more reasonable, more scalable program. This design, develop and debug some large software is particularly important, and the C language structure-oriented programming language, that is process-oriented.
3, C ++ program basic structure
- C ++ program is typically composed of one or more functions, the function is the basic unit constituting the C ++ program. C ++ program must contain at least one main function main (), a C ++ program always starts execution from the main function.
- C ++ function description section composed of two parts and body of a function.
4, program writing rules
- Column written statement with the same level, the same level of additional braces must be on the same column with the corresponding closed parentheses. Each C ++ statements and data must be described with a semicolon; end ()
- Inner retracted position statement two characters
- Defining a first column of a writing function
- Strict distinction between uppercase and lowercase letters
- C ++ I / O: input, output flow is achieved by cin and COUT, for example: cin >> a >> b; input values for variables a and b. cout << "the value is" << m << endl; value for the output variable value.
- Note: in any position of the C ++ program can be inserted into the annotation information, such as / * footnotes * /; // annotation content