Home > Back-end >  Basic knowledge of C
Basic knowledge of C

Time:11-09



A
The emergence and development of c + + :

Evolved from the C language development, was originally called "C with classes";

In 1983, officially named C + +;

In November 1998 by the international organization for standardization (ISO) approval for the international standard;

On October 15, 2003 release version 2 C + + standard ISO/IEC 14882:2003

Released on August 12, 2011, the ISO version 3 C + + standard C + + 11, contains the core language of the new function, extend the C + + standard library

On August 18, 2014, announced the ISO c + + 14, its formal name:

"The International Standard ISO/IEC 14882:2014 (E) Programming Language c + +";

C + + 14 as a C + + 11 small extension, mainly provide bug fixes and small improvements

The characteristics of c + + :

Compatible with C, support process oriented programming;

Supports the object-oriented method;

Supports generic programming method,

A: C + + character set:

1. The case of English letters: A to Z, A to Z

2. The numeric characters: 0 ~ 9

3. The special characters:! # % ^ * _ +=- ~ & lt;>/\; ., '{} | ":? ()

2: keyword (c + + the predefined words) :

Identifier: programmers statement of words, it is named after some entities in the program text

Text
2.
In the program directly using the symbol data

3. The separator

{0} :; Used to separate each lexical markers or text

4. Operator (operator)

Used to implement the various operations of symbol

5. Whitespace

Spaces and tabs (TAB characters), vertical tabs, line feeds, carriage returns, and the floorboard of the annotation

Three: noun definition:

Constant

Directly in the source program data indicating its value cannot be changed during the whole program run, such data as constants,

Variable

In the process of running from the computer peripheral equipment (such as a keyboard, hard drive) is read, the value of the data in the process of the program is running allows the change, such data as variables,

From the keyboard input data

Iostream class object cin & gt;> Operation, can from the standard input device (usually a keyboard) read in data,

Data storage

For these data to store data, need to allocate memory space, the definition of a variable is in when allocating memory for naming a variable space,

Four: integer types:

Basic integer types: int

According to the sign points:

Symbols (signed)

Unsigned (unsigned)

Identifier for the composition of the rule:

* to uppercase letters, lowercase letters or underscores (-)

* can be in capital letters, lowercase letters

The underline (-) or number of 0 ~ 9

* uppercase and lowercase letters represent different

Identifiers

* can't be a c + + keywords or operator


PS: the program execution process not always order so the program to be able to:

To perform process selection (selection, switch statement)

Repeatedly use the same algorithm processing mass data in turn (loop)





2
Four kinds of operations:
Operation, a comma,
Format: expression 1, 2
To solve the order and the results
To solve the expression 1 first, then to solve the expression 2
The final result with the value of expression 2

Second, relationship between operation
Prioritize
<==with priority (high)
==!=the same priority (low)
Relational expression is a kind of simple logical expression
The result type think Boolean type, value can only be true or fales

Three, logic operation
Low priority: high
! (a) & amp; & (and) | | (or)
Logic operation result of type bool value can only is true or false
Logic and... Two true to false, false
Logic or... A false is false is really true, two

Four conditions of operation,
General form
The expression 1? Expression 2:3 cases of X=aExpression 1 must be bool type, the expression of 23 can be different, the final type of conditional expression was higher in 2, and 3
Conditional operator priority is higher than the assignment operator, below the logical operators,

Arithmetic operations and assignment operations:
A basic arithmetic operators,
+ - */integer division results integer

% take over operation for integerSecond, compound assignment operator
A +=3 is equivalent to a=a + 3
A *=b + 8 is equivalent to a=a * (b + 8)
A %=3 is equivalent to a=a % 3
Priority and junction and
First, and then add and subtract, at the same level from left to right
+ +, - (since, the decrement)
Front and rear
Three, assignment operators
The assignment operator "="
Assignment expression a=3 said will be constant and assigned to the variable a
Assignment transformation
(1) the floating-point data (single and double) assigned to the integer variables, abandon the decimal part, such as I as integer variables, the implementation of "I=3.56" the result is to make the I has a value of 3, in memory is stored in the form of an integer,
(2) to assign plastic data floating-point variables, numerical remains the same, but in the form of index stored in variables,
(3) will be assigned to a double data float variable pay attention to the scale not overflow,
(4) is assigned to integer variables, character data to assign the ASCII characters to integer variables,
(5) will be an int, short, long data type is assigned to a char variable, only the low eight intact to the char type variable (truncated),
(6) there will be a sign (signed) data is assigned to the length of the same type unsigned variable (unsigned) type, the content of the storage unit is copied,
The comma operator
The assignment operator priority level is higher than the comma operator



The Sizeof operator
1. The syntactic form
Sizeof (type) or sizof expression

2. The resulting value:
"Type name" formulated by the types, or the result of the "expression" type of bytes
Arithmetic, bitwise and (& amp;)

3. A computing
Algorithm (as)
Two computation of each logic and operation of
3-0 0 0 0 0 0 1 1
5-0 1 0 0 0 0 0 1
3 & amp; 5:0 0 0 0 0 0 0 1
Purpose: to a certain location 0 other unchanged
Remove the specified bit

4. The operation rules (or)
Two computation of each for the operation of the logic or
3-0 0 0 0 0 0 1 1
5-0 1 0 0 0 0 0 1
3 & amp; 5:0 0 0 0 0 1 1 1
Purpose: to certain position 1, other unchanged

5. Algorithm (the bitwise xor)
Exclusive or two operands:
If the corresponding bit is the same, the result is 0
If corresponds to a different, the results a 1
3-0 0 0 0 0 0 1 1
5-0 1 0 0 0 0 0 1
3 & amp; 5:0 0 0 0 0 1 1 0
Purpose: to make specific bits flip (1 and 0 or keep the original value, and exclusive or invert)


Algorithm (DE) by a
Change 1 1 0 0 directly change

Left shift operation (& lt; & lt;)
After left shift, low fill 0, high abandon
Moves to the right operation ()
After moves to the right: low abandon, high: unsigned number is 0, a signed number to fill "number of symbols"




String vector array
1 · namespace using declaration
After use the using statement, you don't need to travel through the special prefix to obtain the required name, using declaration has the following form: using the namespace: : name,
Example: # include & lt; Iostream>
//using declaration, when using name cin, obtain it from the namespace STD

//or use spacename, need not separate call specific statement
//using namespace STD.
Int main ()
{
int i;
Cin & gt;> i;//ok: cin and STD: : cin same meaning
Cout & lt; STD: : cout & lt; Return 0;
}


Every name used in the program need to use using declaration of independence, or need to introduce spacename,

Header file should not contain usually using declaration, this is because the content of the header file will be copied into all references it wipes the files, if there is a using declaration in the header file, then each use the header file would have this statement, for some applications, due to the casual contains some names, but may produce unexpected name conflict,





2, the standard library type string

Standard library type string said variable-length character sequence, defined in the header file string,

1) the definition and the initialization string object

If you are using the equals sign to initialize a variable, in fact, execution is a copy of the initialization (copy initialization), the compiler to initial values on the right side of the equal sign copy to the newly created object, if you don't use the equals sign, an initialization is executed directly (direct initialization),

String s5="hiya";//copy the initialization string s6 (" hiya ");//initialize a string directly s7 (10, 'c');//initialized directly, is the content of the s7 CCCCCCCCCC

2) string object operations on
When performing read operations, the string object will automatically ignore the beginning of the blank (Spaces, line breaks, tabs, etc.) and read from the first real character, until met with a blank,
Note: _Hello_World_ input, there are three Spaces (here with three underlined flagged), respectively, in the front, middle and back, but the output without any Spaces,
When set up multiple input or output, you can even write together,

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related