Home > Back-end >  C based
C based

Time:11-09

Basic knowledge of c + + summary:
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,


C + + character sets and lexical mark
C + + character set
Case of the English letters A to Z, A to Z
Numeric characters: 0 ~ 9
Special characters:! # % ^ & * _ +=- ~ & lt;>/\; ., '" :? (a) [] {} |

The keyword
Identifier: programmers statement of words, it is named after some entities in the program text
Text: in the program directly using the symbol data
Delimiter: () {}, :; Used to separate each lexical markers or text
Operator (operator) : used to implement the various operations of symbol
Operator: blank Spaces and tabs (TAB characters), vertical tabs, line feeds, carriage returns, and the floorboard of the annotation


The composition of identifier rules
With capital letters, lowercase letters, or the underscore start
With capital letters, lowercase letters, underscores or number of 0 ~ 9
Lowercase and uppercase represent different identifiers
Can't be a c + + keywords or operator & gt;

Basic data types, constants, variables,
C + + can handle basic data types:
Integer type real type character types Boolean type
In the program data: constant variable
Integer type
Integer data: a long integer general integer short integer
Basic integer types: int
According to conform to the points: signed unsigned
Floating-point data: single precision double long double

Program, an example is given to outline the

Constant
Data is written directly in the source program, its value cannot be changed during the entire program is running such data as constants,
Variable
In the process of running from computer peripheral devices (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
In order to store data, need to allocate memory space for the data in advance,
Variable is to give the definition of a variable named allocates memory space when


Arithmetic operators and arithmetic expression
Basic arithmetic operators
+ - */(if the integer division, the integer)
% (take, as an integer operands)
Precedence and associativity
+ + - (since, the decrement)
Lead: add or subtract 1 first operation, the value of the variable gain 1, then the variables involved in other operations
Rear: divides the value of this variable inside take out a copy, if it need to participate in a wider range of operation with copy, and add 1
Assignment operation:
to assign values to variablesThe assignment operator,=(not equal to)
Composite operator: +=

The sizeof bit operations

Sizeof: a variable or a data type in the number of bytes, (1) type int type double aren't sure of how many bytes (2) need a custom type a number object of bytes of the whole class, sometimes implied there is no definition but he also generate your data members, together is not necessarily accurate)
Bit operations: (high level language processing data in bytes, machine assembly language processing data is based on a unit)

The sizeof operator
. Grammar form
Sizeof (type) or sizeof expression
. The result value
"Type name" specified type, or the result of the "expression" type of bytes
Example: the sizeof (short) sizeof (variable) x

Arithmetic, bitwise and (& amp;)
The operator.
Two computational complexity of every position by using the Boolean and operator
Example: calculate 3 & amp; 5
3-0 0 0 0 0 0 1 1
5:1 0 0 0 0 0 0 1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
3 & amp; 5-0 0 0 0 0 0 0 1
(write the underlying hardware excuses, or to write program to store some state, some tags useful)
. The use, for example: 1, to a certain location 0, other unchanged,
For example: the char type variable a lowest position 0: a=a& 0 xfe (1111 1110) hexadecimal fe - high seven is 1, the lowest is 0
2, specify a
For example: char c; int a; Take out a low byte, put in the c: c=a& 0 XFF hexadecimal ff (1111, 1111) - low 8 are all 1, high all 0

Arithmetic, bitwise or (|) : two Numbers corresponding to the corresponding binary arithmetic
The operator.
Two computational complexity of every position by using the Boolean or operator
. The case; Calculate 3 | 5
3-0 0 0 0 0 0 1 1
5-0 1 0 0 0 0 0 1
-- -- -- -- -- -- -- -- -- -- -- -- -- -- --
3 | 5-0 0 0 0 0 1 1 1
Purposes, for example: to certain position 1, other unchanged,
For example: int variable a low byte buy 1: a=a | 0 XFF

Bit operations - the bitwise xor (^)
The operator.
Exclusive or two operands:
If the corresponding bit is the same, then the results the bit is 0;
If the corresponding bit is different, the result the bit is 1;
. For example: 075 ^ 052
075:1 1 1 1 0 0 0 1
052:1 0 0 0 0 1 0
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
075 ^ 052:1 0 0 0 0 1 1
Purposes, for example:
Make a variable specified inside a flip (1 and 0 or keep the original value, and exclusive or invert)
For example, to make the 01111010 low turn four:
1 1 1 1 0 0 0
0 0 0 0 1 1 1 1
(^) -- -- -- -- -- -- -- -- --
1 1 1 0 0 0 1

Bit operations - the not (~)
The operator.
Unary operators, for a binary number in an invert
. Example: 025-0000000000010101
~ 025:1111111111101010

Bit operations - shift (& lt; <, & gt; & gt;)
Left shift operation (& lt; & lt;)
After left shift, low fill 0, high abandon
Moves to the right operation (& gt; & gt;)
After moves to the right, abandoned, low high 1. Unsigned number: fill 0
2. A signed number: fill "the sign bit
"

Logic conditions of comma relationship


Comma: connection between the two expressions about first left after the right to the right of expression is the finish
Relationship: to compare the two expressions of size
Logic: logic and logic or logic not
Condition: very simple choice structure

Comma operation and comma expression
The format
The expression 1 2
To solve the order and the results
To solve the expression 1 to 2
The final result with the value of expression 2
Example:
A=3 x 5, the end result is a * 4 60

Operation and relationship expression
Relationship between operations is one of the simple logic operations, priorities for: & lt; Or less & gt; P==!=
Same (high) priority priority (low)
Relational expression of its result type bool, values can only is true or false
For example: a> B, c or less a + b, x + y==3


Logical operators and logic operation expression
Logical operators
! (a) & amp; & (with) lots (or)
Priorities: high? Low
Logic operation result types: bool, values can only is true or false
& & The algorithm of
On both sides of the result is true is true, have a side is false is false
Lots of algorithms
Results on both sides are all false is false, there is a side is true is true

Conditional operator and conditional expression
General form
The expression 1? Expression 2:3
Expressions must be bool type 1 (if 1 is true for 2, 2 for the final result; If 1 to false for 3, 3 for the final result)

Operation conditions of priority
Conditional operator priority is higher than the assignment operator, below the logical operators
Expression must be bool type 1
Conditional expression eventually type for 2 and 3 high



Simple programming

Annotation
Proper annotations, can improve the readability of the program, and make some code snippet temporarily need not, is to modify the sample application tool
Annotation method
Method one:/*... */
Method 2://... In a line with the tail end of ()

Auxiliary debugging tool
Auxiliary debugging tool that can be used to achieve single-step operation, set breakpoints, and the function of the variables and the value of the expression


Positioning to exclude runtime error is called the program debugging
  • Related