"Review of C + +" 1.1 Basic concepts

Source: Internet
Author: User

1, C + + is sensitive to case;2. View running results
Cin. Get (); Cin. Get ();

Use two lines of code to cause the program to pause after it is run, instead of ending immediately, with a flashback effect.

The first cin.get () statement reads the input as it is entered and presses the ENTER key, and the second cin.get () statement pauses the program until the ENTER key is pressed.

3. The function header describes the interface between the function and the function that called him

The part before the function name is called the function return type, and the part of the function name after the parentheses is called the parameter list (argument list) or the argument list (parameter list).

4. header file name

C-style: End with extension. h, eg:math.h;

C + + style: No extension, some C header files are changed to start with C, remove. H,eg:cmath;

For C + + header files, you can use namespaces.

5. Line break

C + + control character (manipulator): Endl.

C language symbol: \ n. \ n is treated as a character, and is called a line break. (Escape sequence)

Both of these methods float the cursor to the next line.

cout<<"start C + +. "<<endl;  // show Text,go to next     line cout<"start c++.\n"/   /show Text,go to nextline//  generate empty lines  <<\ n; cout<<endl;

When you display a quoted string, you typically use a newline character and, in other cases, the control Endl. The difference is that Endl ensures that the output is refreshed before the program continues to run (it is immediately displayed on the screen), and that using "\ n" does not provide such a guarantee.

6. C + + source code style
    • Each statement occupies one row.
    • Each function has a start curly brace and a closing curly brace, each of which has a row of curly braces.
    • The statements in the function are indented relative to the curly braces.
    • There is no white space around the parentheses associated with the function name.
7. Statement
int carrots;

A declaration typically indicates the type of data to store and the name that the program uses for the data stored here.

A declaration statement in a program is called a definition declaration (defining declaration), which is referred to as definition. There is also a declaration called citation (Reference Declaration). These declarations command the computer to use variables defined elsewhere. Typically, a declaration is not necessarily a definition, but, as above, a declaration is a definition.

In the C language, a variable declaration is usually at the beginning of a function or procedure. However, C + + does not have this limitation.

C + + is typically declared only before the first time a variable is used. (The C99 standard makes C declaration rules very similar to C + +)

8. Class: A class is a user-defined data type.

The class describes all the properties of a data type, including the operations that can be performed with it, and objects are entities created from these descriptions.

9. Functions
// function Prototype Declaration void Simon (int);int  main () {    ...     return 0 ;} // function Definition void Simon (int  n) {}

Function Prototype declaration: Know the parameter type and return value type of the function.

Function prototypes differ from function definitions: Prototypes only describe function interfaces, which describe parameters and return values.

The return value of main:

The return value of main is not returned to other parts of the program, but is returned to the operating system. The usual convention is that an exit value of 0 means the program is running successfully, and zero means there is a problem. Therefore, if a C + + program cannot open the file, it can be designed to return a non-0 value. You can then design a Unix shell script or Windows command-line batch file to run the program, and if the program issues a message that indicates a failure, take additional action.

10. Using a compiler directive in a multi-function program

4 ways to access the namespace std:

    1. Put the using namespace STD, before the function definition, so that all the functions in the file can use all the elements in the namespace Std.
    2. The using namespace STD is placed in a specific function definition so that the function can use all the elements in the namespace Std.
    3. Use a similar using std::cout in a specific function, such as a compile instruction, rather than using namespace STD, to allow the function to use the specified element, such as: cout.

The use of the compile instruction is not used at all, but when the element in the namespace STD needs to be used, the prefix std::, as follows:

std::cout<< "I ' m using cout and Endl from the Std namespace" <
   
11, six kinds of C + + statements
    • Declaration statement-Defines the name and type of the variable used in the function.
    • Assignment statement-assigns a value to a variable using the assignment operator (=).
    • Message statement-sends a message to an object, triggering an action.
    • Function call-execute function. When the called function finishes executing, the program returns to the statement following the function call statement.
    • Function prototype-declares the return type of the function, and the number and type of parameters required by the function.
    • Return statement-Returns a value from the called function to the calling function.

"Review of C + +" 1.1 Basic concepts

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.