.
: , , , . ++ . ++ .
+ (): +x, x+y
- (): -x, x-y
* (): x*y
/ (): x/y
% ( ): x%y
.
() C++ ( ) , .
() C++ , ( ) .
1.2. .
, :
( ) &;
( ) |;
^;
~.
<<;
>>;
.
& .
|
^ , : x=x^y, y=x^y, x=x^y
<< ( ) , . 1 2. .
>> ( ): , . , = 0. 1 2. .
(. . ) , ,
,
! ()
|| ( )
&& ( )
1.4. ().
, , - . . , : 0 (false), 1 (true).
,
( ),
.
true false.
1.5. . , .
! -( ) + + + - -()
* / %
+ -
<< >>
< <= > >= = =!=
&
^
|
|
|
&&
||
?: ( )
. , , , . , .
, -. , , , , .
, , , . , , ; . , .
, .
:
(<>) <>
.
(int) (1.5 / 0.3); // int
(float) (1.5 / 0.3); // float
.
break
switch .
continue.
continue (for, while do-while) . , continue, .
goto.
goto , . , switch -.
: goto ;
exit()
it() . , .
2.5. if else.
( ), true , ( ), false.
:
if () ;
else ;
(, , , , ).
. ( ). , .
else if
if else else-if-, , .
if () ;
else if () ;
else if () ;
else ;
|
|
, .
true (1), elseif - .
true, , else.
else - , , , - .
switch
switch .
switch () {
case _1: ; break;
case _2: ; break;
case _3: ; break;
case _m: ; break;
default: ;
}
. switch- case- .
, case-, , switch- . case- , default-, , switch .
case - , , switch -. , case -, () break ( ). break switch -, .
for
for . for - : for (1; 2; 3) ;
1 . 1 , . 1 , . 1 .
2 (.. 2 , , ). 2 , , . , .
3 . . 3 , . 3 . 3 .
. . , .
3.2. for(;;) for. , for , .
break, .
do-while
++ do do-while. while , do . , , . :
|
|
do
while ();
while
while . while- :
while ()
; //
, , . .
. ( ). , .
while , .
(false) .
while false (0), .
(a, b).
1. a b r
2. r = 0, (a, b) = b
3. r <>0, 1 (b, r)
do
if (a>b)
a%=b;
else
b%=a;
while ((a!=0) && (b!=0));
a b. .
int a,b, tmp;
{1}
tmp = a; a = b; b = tmp;
{2}
a = a + b; b = a - b; a = a - b;
{3}
a = a ^ b; b = a ^ b; a = a ^ b;
. .
, "", , .
, .
int Count_Bit(int a)
{
int bit;
int mask = 1;
int num = 0;
for (int i = 0;i <=31;i++)
{
bit=mask & a;
if (bit == mask) num++;
mask = mask << 1;
}
return num;
}