C + + Basic review (data types, control statements, arrays)

Source: Internet
Author: User
Tags logical operators

In the last two days, we opened the C + + Textbook of undergraduate school and quickly reviewed the contents of C + +. Although the book content is relatively basic, but still some knowledge points worthy of self-reinforcing memory. Several articles, together with their own understanding of the record as follows.

Review the process-oriented section first.

C + + data types

1. Data type modifier:

1.1 Long can not only modify int, but also modify double, while short can only modify int;

1.2 The data type of "modifier only" is shorthand for "modifier int", such as unsigned long is a shorthand for unsigned long int.

2, integral type constant: Octal number starts with 0, hexadecimal number starts with 0x or 0X.

3. Floating-point constants: 1.23*10^4 can be represented as 1.23E4 or 1.23e4 in C + +.

4. Escape character:

4.1 If the escape character is followed by an integer constant, it must be an octal number prefixed with 0 (note that prefix 0 can be omitted), or hexadecimal number prefixed with X (note X instead of 0x);

4.2 If the escape character is followed by a character, its character must be lowercase and uppercase can only represent itself. such as ' \e ' think is ' E '.

5. Variables:

5.1 The variable name is actually a symbolic address that is assigned to each variable name by the system when it compiles the connection to the program. Taking a value from a variable in a program actually reads the data from its storage unit by locating the corresponding memory address from the variable name.

5.2 C + + requires variables for mandatory definition purposes:

5.2.1 is not defined in advance and is not used as a variable name to ensure the correct use of variable names in the program;

5.2.2 each variable is designated as a deterministic type and can be assigned a corresponding storage unit at compile time;

5.2.3 is able to check the validity of the operations performed by the variable type at compile time. (such as: A, B is a real variable, the remainder operation is not allowed)

5.3 #define定义的符号常量和const定义的常变量的区别:

Symbolic constants simply replace a sequence of characters with a single symbol, replacing all symbolic constants with a specified sequence of characters when compiling preprocessing, which has no type, and there is no storage unit in memory named after the symbolic constant;

The constant variable has the characteristics of a variable, it has a type, and in memory there is a storage unit named after it.

Common variables are commonly used in 5.4 C + +. Because the const statement is used to define a constant variable with a data type, it is convenient for the system to type check, and it also has the function of calculating the initial value expression.

6, in the solution of the logical expression, not all the logical operators are executed, but only when the next logical operator must be executed to find the solution of the expression, the operator is executed.

6.1 such as a | | B | | C, as long as a is true, you do not have to Judge B and C;

6.2 such as int a = 1, b = 2, c = 3, d = 4, M =5, n = 6; BOOL X; x = (M = a > B) && (n = c > D); After execution, the value of n is not 0, but it is still 6.

7. Comma operator:

7.1 int A; (A = 3 * 5, A * 4), A + 5; After execution, A is 15, and the second statement has a value of 20 for the entire expression;

The 7.2 comma operator is the lowest level in all operators.

Program Control statements

1. If...else ... Statement, else is always paired with the last if closest to it.

2. Switch...case ... Statement, the case is followed by a constant expression (which cannot be a normal variable), and the value of the constant expression must be an integer, a character, or an enumeration type.

3, for (statment1; statement2; statement3), if the For loop has execution to the continue statement, jump to execute statement3 and proceed to the next round of loops.

Arrays and struct bodies

1. String Processing:

1.1 Gets (str) is the function of entering a string from the terminal to a character array, and a function value, which is the starting address of the character array. (The following STR starts with the char * type)

Expansion: Cin.get (str, size), reads a whole line at a time, and leaves the newline character generated by the ENTER key in the input queue, typically combined with: cin.get (str, size). get ();

cin.getline (str, size), every time a whole line is read and the newline character generated by the ENTER key is discarded; usage is almost the same as get (str), just one more size parameter;

Getline (cin, String), which reads an entire line at a time, and is of type string;

GetChar (CH), accepts a character.

The role of 1.2 puts (str) is to output a string (a sequence of characters ending with ' \ s ') to the terminal.

1.3 strcat (strdest, strsource) is the address of a character array strsource that is returned after the string strdest is concatenated to the string strdest.

1.4 strcpy (strdest, strsource) is the The string strsource is copied to the character array strdest, returning the address of the strdest to the character array.

1.5 strcmp (str1, str2) compare str1 and str2, if str1 = = str2, return 0; If str1 > str2, return a positive integer; if str1 < str2, returns a negative integer.

1.6 strlen (str) returns the actual length of the string, not including '/'.

Cin.get ()

Each time a full line is read and the

Enter

The line breaks generated by the key are left in the input queue

C + + Basic review (data types, control statements, arrays)

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.