2.
C++, , , .
:
- ;
- , ;
- , ;
- .
2.1 C++
, C++, , main. main.
, . ( , .) .
:
_ int main() { _; ; return 0; } | _ void main() { _; ; return; } |
(main), ( main ). . , void. , . return 0; , 0.
main , , . , . , ;.
. , , . , , . . , , . - , .
, . , , - , . , . . , , , , . , , , , , . C++ , , .
|
|
C C++ .
1. , . , . , , .
1 ,
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | |
a b c d e f g h i j k l m n o p q r s t u v w x y z | |
_ |
2. .
2
0 1 2 3 4 5 6 7 8 9 |
3. . , .
3
, | ) | ||
. | ( | ||
; | } | ||
: | { | ||
? | < | ||
' | > | ||
! | [ | ||
| | ] | ||
/ | # | ||
\ | % | ||
~ | & | ||
* | ^ | ||
+ | = | ||
- | " |
4. . : , , , , . , , . ( ).
5. C C++ , , .. , . (\) ( ) .
4
|
|
\a | ||
\b | ||
\t | ||
\n | 00A | |
\v | 00B | |
\r | 00C | |
\f | 00D | |
\" | ||
\' | ||
\0 | - | |
\\ | 05C | |
\0ddd | ||
\xddd |
\0ddd \xddd ( d ) . , :
\r - ,
\015 - ,
\x00D - .
, . , \n ( ) \010 \xA, , , , . :
"ABCDE\x009FGH" C++, ABCDE FGH, ( 8- ), "ABCDE\x09FGH", ABCDE=|=GH, \x09F "=+=".
, , (.. 4) , , . , \h h .
, (\) . (\) (\n), , . .
, , , .. .
C++ , . , . . :
abc A12 NameOfPerson BITES_PER_WORD
abc Abc , .. . :
23X a-b
C++ . .
:
asm auto bad_cast
bad_typeid bool break
case catch char
class const const_cast
continue default delete
do double dynamic_cast
else enum extern
float for friend
goto if inline
int long mutable
namespace new operator
private protected public
register reinterpret_cast return
short signed sizeof
static static_cast struct
switch template then
this throw try
type_info typedef typeid
union unsigned using
virtual void volatile
while xalloc
, . . , ( , ) .
|
|
, , . .
C++ , . x : int x;
int ( ), x . x . , . , .. x , .
C++ . , , - . , . .
, x+y, x , y .
. , ( ). . , , , , , .
C++ . , , :
char short int long float double
, . char , (, ), int , (, ). , , . C++ char, char .
, , .
char 1 -128 127
int 2 -32768 32767
short 2 -32768 32767
long 4 -2 147 483 648 2 147 483 647
unsigned char 1 o 0 255
unsigned int 2 0 65535
unsigned short 2 0 65535
unsigned long 4 0 4 294 967 295
, -: float, double, long double.
- float 4 . 1 , 8 23 . , 1, , 3.14E-38 3.14E+38.
double 8 . float. : 1 , 11 52 . 1.7E-308 1.7E+308.
|
|
, .. , x + 4 x 4. , , x . . , .
. const. ,
const int BITS_IN_WORD = 32;
BITS_IN_WORD 32.
. , . . . :
- ( );
- ( ).
- . . - , , .
int x; // x
int y; // y
x = 0; // x 0
y = x + 1; // y x + 1, .. 1
x = 1; // x 1
y = x + 1; // y x + 1, 2