, . - , ( ). , . - ; .
" " " ". - , , , - . , , - . , :
- char - ;
- int - ;
- float - ;
- double - ;
- void - .
:
- char 1 , , : '', ':', 'j' ( ).
- int . int . , 16- int 2 . -32768 32767.
- float . , , : -5.6, 31.28 .. , : -1.09e+4. "" , "" - . float 32 . 3.4-38 3.4e+38.
- double . , float (.. 64 ). double 1.7e-308 1.7e+308.
- void ( ) , , , .
. , . ANSI :
- unsigned
- signed
- short
- long
, : unsigned char. , , int. , :
long ;
long int ;
. . 1 (unsigned, signed, short, long) (char, int, float double), ( 16- ).
|
|
() | ||
char | 1 (8) | -128 127 |
unsigned char | 1 (8) | 0 255 |
signed char | 1 (8) | -128 127 |
int | 2 (16) | -32768 32767 |
unsigned int | 2 (16) | 0 65535 |
signed int | 2 (16) | -32768 32767 |
short int | 2 (16) | -32768 32767 |
unsigned short int | 2 (16) | 0 65535 |
signed short int | 2 (16) | -32768 32767 |
long int | 4 (32) | -2147483648 2147483647 |
unsigned long int | 4 (32) | 0 4294967295 |
signed long int | 4 (32) | -2147483648 2147483647 |
float | 4 (32) | 3.4-38 3.4+38 |
double | 8 (64) | 1.7-308 1.7+308 |
long double | 10 (80) | 3.4-4932 3.4+4932 |
(). , , . :
int a, b, c; char x, y;. : (, ), (, 4 ) .. ( ).
, :
float a; float b;:
int a = 25, h = 6; char g = 'Q', k = 'm'; float r = 1.89; long double n = r*123;, . . , , . . , . , .
int a; /* */ int function (int b, char c); /* (.. )*/ void main (void){ // int d, e; // float f; // ... }
:
- , 123.456, 5.61-4. F ( f), 123.456F, 5.61e-4f;
- , 125;
- , () H ( h), 275h, 344H;
- , () L ( l), 361327L;
- , U ( u), 62125U;
- , (0), 071;
- , - (0x), 0x5F;
- - , , '', '2', '.' .. , , , , \n ( 10), \0 ( 0). , . : '\NNN', NNN - . , : '\2', '\6' ..;
- - , , : " ". , . , '\0'. , , , ;
- , , (: =60+301);
- long double, L ( l), : 1234567.89L.
|
|
(, .), . - , , .
. , , . . 2 . ( ). , . .
2
() | |
[ ] | |
. | |
-> | |
! | |
~ | |
- | |
++ | |
-- | |
& | |
* | |
() | (.. (float) a) |
sizeof() | |
* | |
/ | |
% | |
+ | |
- | |
<< | |
>> | |
< | , |
<= | |
> | , |
>= | |
= = | |
!= | |
& | "" |
^ | "" |
| | "" |
&& | "" |
|| | "" |
?: | () |
= | |
+=, - =, *=, /=, %=, <<=, >>=, &=, |=, ^= | (, *= b (.. a = a * b) ..) |
, |
"" "", , - . , (: a = sin(b)+c; j++;), , , , , .. . ( ), , ({) (}) (" "), . , .
. - (=).
= ;. "=" , :
x = y = z = 100;. , - . , :
|
|
- .
- .
- .
(. 2): +, -, *, /, %. . :
a = b + c; x = y - z; r = t * v; s = k / l; p = q % w;(. . 2): && (""), || (""),! (""), >, >=, <, <=, = = (),!= ( ). : . : - ; - . , , 0 1 . .
3
x | y | x&&y | x||y | !x |
, int, char, (, long int). float, double, void ( ). : ~ ( ), << ( ), >> ( ), & ( ""), ^ ( ""), | ( "").
: a = 0000 1111 b = 1000 1000,
~a = 1111 0000, a << 1 = 0001 1110, a >> 1 = 0000 0111, a & b = 0000 1000, a ^ b = 1000 0111, a | b = 1000 1111.(++) (--). . ++ -- , . (++n --n) (n) , (n++ n--) - . :
a = b + c++; a1 = b1 + ++c1;, b = b1 = 2, c = c1 = 4. : a = 6, b = 2, c = 5, a1 = 7, b1 = 2, c1 = 5.
?:.
y = x? a: b;y = a, x (.. ), y = b, ().
y = (a>b)? a: b;( b), .. y = max(a, b).
, = + 5; : a += 5;. + (. . 2).
, , :
- long double, long double.
- , double, double.
- , float, float.
- , unsigned long, unsigned long.
- , long, long.
- , unsigned, . unsigned.
- int. char int ; unsigned char int, ; signed char int, har; short int ( ).
, . , . : . , .
|
|
. ("") . :
()( ).
:
int a = 30000; float b;........ b = (float) a * 12;( a float; , , .. a * 12 > 32767).
- , , (, .). , .
& ,
= &;. & ; &(+7) &28 .
* ,
z = *y;z , .
y = &x; z = *;z = x.
, * (, *), . , , :
int *, *b, *; char *d;char *d , , d, char.
. - , .. int *, * , , . , :
* = 7; *x *=5; (*z)++;7 , , z. , . , , *z = 5, (*z)++ , *z = 6, *z++ z ( ++ z, *z ).
. - , y++ ; . . + n ( - , n - ) n-o , . (int, char, float .); , .
(==) (!=) NULL, .
, . : for, while do - while. , :
for (_1; _2; _3) _, , {... } ( ). 1, 2, 3 , . .
_1 , _ , _2 , , .
|
|
:
for (i = 1; i < 10; i++) {... } for (h = 'a'; ch!= 'p';) scanf ("%c", &ch); /* , 'p' */for , . , for (;;) {...} - , .
. , , , . , (=7+2) 9. , : ((=7+2)<10), . :
((h = getch()) == 'i')h , 'i'. , . . , . , char,
z = ( = , = getch());: ; ; z . , , , z. for .
, .. for.
while :
while () _() () . , . , while .
do-while :
do {_} while ();while do - while , do - while . , . , .
, .. for, while do - while.
break continue. break , continue .