int a,b;
int &alt=a; // alt ( a)
alt = b; // a=b;
alt++; // a++;
int *ptr = &a;
:
*ptr == alt; // ,
ptr == &alt; // ,
, , *.
, .
:
const char &new_line='\n';
temp :
char temp = '\n';
const char &new_line = temp;
++ . :
, ;
, .
, :
-, ,
-, , .
. , :
void swap (int *a, int *b) { int temp = *a; *a = *b; *b = temp; } | void swap (int &a, int &b) { int temp = a; a = b; b = temp; } |
: int x = 10; int y = 5; swap(&x, &y); | : int x = 10; int y = 5; swap(x, y); |
, :
, , . , , , const. , const .
, ++ , .
void swap (int &, int &);
int main() {
int x=10;
unsigned int y;
y=5;
swap(x, y);
...
}
:
int temp = (int)y;
int &t = temp;
swap(x, t);
swap() x temp. temp , y .
++ , . . ,
, return; .
|
|
, return . ( , ).
.
5
1: C..
:
;
;
;
;
c .
.
. , .
= 2 :
;
, :
= ;
:
int a = 4; // a 4
int b;
b = a + 2; // b 6,
//
.
= ();
float a = 241.5;
// a
int b = (int)a % 2; // b = 1
:
== ;
!= ;
< ;
> ;
<= ;
>= .
. 1 , 1, - , 0, - .
, :
*;
/;
+;
-;
%.
:
( 1) ++;
( 1) --;
-.
, , , ( ).
, 1, . ++ -- , , 1.
:
int a=2; int b=3; int c; c = a*++b; // c=8, b=4 | int a=2; int b=3; int d; d = a*b++; // d=6, b=3, b=4 |
:
*= ; // = *
/= ; // = /
+= ; // = +
-= ; // = -
%= ; // = %
:
;
.
if . :
|
|
1 ;
0 .
, , , .
:
&& - () ;
|| - () ;
! - () .
, : 0 1.
:
& ( ) - , 1 ( - );
| ( ) - , 1 1;
~ ( ) - , 0 , 1, ;
^ - , 1, 1 ( ).
.
a | b | a & b | a | b | ~a | a ^ b |
:
unsigned char a = 14; // a = 0000 1110
unsigned char b = 9; // b = 0000 1001
unsigned char c, d, e, f;
c = a & b; // c = 8 = 0000 1000
d = a | b; // d = 15 = 0000 1111
e = ~a; // e = 241 = 1111 0001
f = a ^ b; // f = 7 = 0000 0111
. . , ,
0x01 | |
0x02 | |
0x04 | |
0x08 | |
0x10 | |
0x20 | |
0x40 | |
0x80 |
1 , :
unsigned char a = 3;
a = a | 0x04; // a = 7, 2
0 , :
unsigned char a = 3;
a = a & (~0x02); // a = 1, 1
:
&= ; // = &
|= ; // = |
^= ; // = ^
:
>> - ;
<< - .
:
= ;
:
unsigned char a=6; // a = 0000 0110
unsigned char b;
b = a >> 1; // b = 0000 0110 >> 1 = 0000 0011 = 3
>> 1 2.
<< 1 2.
2:
- - , . , .
. , - .
|
|
. , .. , . , , , ( ).
, . , , Turbo Vision.
. - , () .
. , , , , .
.
- (.. , ) . . , . , .. . - - , , , . .
, (. ), .