, , , , , . . , , .
, . 70- . . , .
, , . : , , .
++.
- .
:
- ;
- ;
- ;
- ( , ).
:
- :
- () ;
- ;
- ;
- (, , ).
. , . , , max, MAX, Max . , . . , .
!!! .
()
. , . ++.
++
asm auto bool break case catch char class const const_cast continue default delete do double dynamic_cast | else enum explicit extern export false 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 | this threw true try tyopedef typeid typename union unsigned using virtual void volatile wchar_t while |
|
|
, (). . ( ), ( ) ( ). - , .
. , , .
8, 0, 223196 ()
0, 08
5.7.001 35.
A z db ( )
"Ivan" .
:
- , (\ );
- (), (\), (?) ().
, , escape-. . .
\a \b \f \n | () |
\r \t \v \\ \ \ \? |
. , , :
\ \
. ( ) :
//
/* */:
/* */.
:
- ;
- , ;
- , .
++ . ++ , , . . , , , , , , .
() :
- int ();
- char ();
- wchar_t ( );
|
|
- bool ();
- float ();
- double ( ).
(), − .
, :
- short ();
- long ();
- signed ();
- unsigned ().
int , . 16- 2 , 32- − 4 . short int , 2 .
signed (0 − , 1 − ). unsigned . , .. signed .
char , . , 1 . char . -127 +127. unsigned 0 255.
wchar_t , 1 .
bool true () false (). false − 0. true.
C C++ : double, float long double. IBM − float 4 , double − 8 , long double − 10
void
void, . , , , .
++ , . main. . :
__ _ ([])
{ ,
}
:
1. , void.
2. .
3. .
4. ( ).
. , main, f1 f2.
int main () {
}
int f1 () {
f1
}
int f2 () {
f2
}
( ).
− , . .
:
[ ] [const] [];
[ ] , .. , . : auto, extern, static register (. ). const , . . , . , . .
|
|
short int a=1;
const char c='c';
char s, sf='f'; // sf
int t(54);
float d=0.22, x(3), sum;
!!! , (. ).
, , .
− , . .
( , ), , , . , , .
. , .
( ) ( ).
− , . . , . , .
:
- auto − . ;
- extern − ( );
- static − . ;
- register − auto.
int a; // 1
int main () {
int b; // 2
extern int x; // 3
static int c; // 4
a=1; // 5
int a; // 6
a=2; // 7
return 0;
}
int x=4; // 8
!!! (. . ).
, , , .
( ).
++
++ | 1 |
-- | 1 |
sizeof | |
~ | |
! | |
- | |
+ | |
& |
* | |
new | |
delete | |
(type) | |
* | |
/ | |
% | |
+ | |
- | |
<< | |
>> | |
< | |
<= | |
> | |
>= | |
== | |
!= | |
& | () |
^ | |
| | () |
&& | |
|| | |
?: | () |
= |
|
|
*= | |
/= | |
%= | |
+= | |
-= | |
<<= | |
>>= | |
&= | |
|= | |
= | |
, |
(++ --) : ( ) ( ). , ; , :
...
int x = 3, y = 3;
printf (" : % d \ n", ++ x);
printf (" : % d \ n", y ++);
...
:
: 4
: 3
sizeof :
sizeof
sizeof ()
sizeof (float) 4 ( float).
sizeof ( + 0.1) 8 ( float) − , double, . . 6 .
. (+=, -= ..) :
...
int a = 3, b = 5, c =4;
c = b + c;
a += b; // a = a + b
...
?: − . :
_1? _2: _3
(, , false, − true). 1 true, 2, − 3. if.
int a = 11, b = 4, max;
max = (b > a)? b: a;
printf (" : % d", max);
:
: 11
, .
(a + 0.12) / 6
x && y ||! z
(t + sin (x) - 1.5e4) / (2*k + 2)
. . , , , − .
a = b = c; // a = (b = c)
a + b + c; // (a + b) + c
. , a, b − :
int a = 2, b =5;
a + b 7 int.
. , . , , .
:
- ;
- .
, , ; − .
(. ).
-
-
int scanf (const char* format,...) //
int printf (const char* format,...) //
format. , ( ) ( ) , , %, .
|
|
. , - .
# include <stdio.h>
int main () {
int i;
printf (" \n");
scanf ("%d", & i);
printf (" %d", i);
return 0;
}
, -. printf \n. scanf i ( & ). %d .
c − .
d, i − .
e, E − .
f − .
g, G − %e %f, ; .
O − .
p − .
s − .
u − .
x, X − .
% − %.
, . − , , , − ():
- % - minC %minC
- % - min.precisionC % min.precisionC
− ; min − , . precision, , , :
- ( %s) precision ;
- ( %f %e) precision ;
- ( %d %i) precision . , precision, .
"-" , , , . .
++
- ++ - cin cout , << >> (. ++. 4. ).
# include <iostream.h>
int main () {
int i;
cout << " \n";
cin >> i;
cout << " " << i;
return 0;
}
""
, , , .
i ++; //
a = d + c; //
fun (i, k); //
if
if . :
if () _1; [else _2;]
. ( true), , − . else ( ). - , ( ). , .
if (a < 0) b = 1;
if (a ++) b ++;
if (b > a) max = b; else max = a;
if (a < b && a > d) b ++; else {b = a; a =0;}
− (= =) (=), :
if (a = 1) b =0;
, , . b .
− . , 0 < x < 1, :
if (0 < x < 1)...;
. :
If (0<x && x<1)...;
, . sqrt ( <math.h>).
switch
switch () . :
switch () {
case __1: [__1]
case __2: [__2]
...
case __N: [__N]
[default: ]
}
( ), ; .
. , :
# include <iostream.h>
int main () {
char op;
cout << " "; cin >>op;
switch (op) {
case '0': cout << " 0"; break;
case '1': cout << " 1"; break;
// switch
case '9': cout << " 9"; break;
default: cout << " ";
}
return 0;
}
− . iostream.h, - cin cout.
break .
:
while () ;
, . , . false, .
-, .
:
do while ();
, , . , . , false.
for
:
for (; ; ) ;
, . , , :
for (int i = 0, j = 2;...
int k, m;
for (k = 1, m = 0;...
, , .
: , bool, true, . .
. , .
.
. , 1 100:
int s=0;
for (int i = 1; i <=100; i ++) s += i;
!!! for , .
, y=sin(x), a<=<=b, a, b . , .
:
goto ;
, goto, :
: ;
goto . − , , .
!!! if, switch . , , , , .
break
break , , , break.
continue
continue , , .
return
return .
:
return [];
. void, .
, ,
int i =10;
. , . . .
++ − , void, .
"" ++. 2. .
, . :
* ;
, (. ); − . , , , .
int *a;
float *b, *c, *d;
void , (, ).
, .
int i; //
const int ci; //
int *pi; //
const int *pci; //
int *const cp=&i; // -
const int *const cpc=&ci; // -
. − , . , , . − .
, .. .
:
1. :
int a = 5;
int *p = &a;
int *p1(&a); // ,
int *r = p;
2. :
char *vp = (char*)0xD8000000;
0xD8000000 − ; (char*) − : " char".
3. :
int *s = 0;
int *p = NULL;
NULL − -, 0.
4. :
int *n = new int;
int *m = new int (10); //
int *u = (int*) malloc (sizeof (int)); //
, new, delete, , malloc, − free. - .
delete n;
delete m;
free (u);
: , (*), , , , (++), (--), , . (&).
, , , :
char a;
char *p = new char;
*p = 'A'; a = *p;
unsigned long int A = 147483647;
unsigned short int *pi = (unsigned short int*)&A;
.
( , , ) , , .
, . , . :
& ;
− , ; & − , , .
int kol;
int & pal = kol; // pal − kol
const char & cr = '\n'; //
:
1. - .
2. .
3. , .
4. , .
(. ++. 2. ).
. , .
. ++ : , , ,
float a[10];
. , . . , , , , :
int b[5] = {3, 2, 1} // b[3] b[4]
:
const int n = 10;
int marks[n]={4, 4, 5, 3, 4};
new, , :
int n = 100;
float *p = new float [n];
- float, , 100 , p. , .
, , .. , , . , , :
p[5] *(p+5).
− malloc :
int n =100;
float *q = (float*)malloc(n*sizeof(float));
, new [ ], delete [ ], , malloc, − free:
delete [ ] p;
free (q);
: , , .
, − .
sizeof (). , , , :
short int *p = new short [5];
p++; // p 2 ()
long *q = new long [5];
q++; // q 4 ()
(*p)++ , .
. :
*p++ = 10;
, , . , , p, 10, , . :
*p = 10; p ++;
1. , 10 .
2. , ( ).
3. , ( ).
, :
int matr [6] [8];
6 8 . . : matr [i] [j] *(matr[i] + j)
*(*matr + i) +j).
!!! .
, , ():
int mass1 [3] [2] = {{1, 1}, {0, 1}, {1, 0}};
int mass2 [3] [2] = {1, 1, 0, 1, 0, 1};
new ( ), :
int nstr = 5;
int **m = (int**) new int [nstr] [10];
, :
int nstr, nstb;
cout << " ";
cin >> nstr >> nstb;
int **a = new int *[nstr];
for (int i = 0; i < nstr; i + +)
a[i] = new int [nstb];
...
, A[4, 5].
, -. - − , , '\0'. - . .
char str[10] = "";
// 10 0 9
, :
char str[ ] = "";
char *str = "";
, , .
:
har *str [10];
.
(. " " ++. 2).
++ string, , , (. "" ++. 4).
!!! cin , . :
char str [100];
cin >> str;
" " str "". (.. '\n') get getline (. " ").
. , :
# include <stdio.h>
# include <string.h> //
int main () {
char s[5], passw[ ] = "bond";
printf (" : \n");
gets(s); //
if (strcmp(s, passw) = = 0) printf ("\n \n");
// strcmp() −
else printf ("\n \n");
return 0;
}
, , (. . , ). (, a , ).
,
, , . , , . ++ .
typedef:
typedef _ [];
typedef unsigned int UINT;
typedef char Msg [100];
, :
UINT i, j;
Msg str [10];
. , . :
enum [_] { };
, .
enum digit {one = 1, two = 2, three = 3};
enum Err {ERR_READ, ERR_WRITE, ERR_CONVERT};
Err error;
digit dig;
ERR_READ, ERR_WRITE, ERR_CONVERT () 0, 1, 2 .
.
:
struct [_] {
_1 _1;
_2 _2;
_n _n;
} [ ];
, .
. , .
struct {
char fio [30];
int date, code;
double salary;
} stuff [100], *ps; //
struct Worker {
char fio [30];
int date, code;
double salary;
}; // Worker
Worker staff [100], *ps; // Worker
:
struct {
char fio [30];
int date, code;
double salary;
} worker = {"", 31, 215, 3400.50};
.
. .
. () -> :
Worker staff [100], worker;
strcpy(worker.fio,Ivanov); //
// C (<string.h>)
stuff[1].code = 215;
Worker *ps = new Worker; // Worker
ps ->salary = 1200.12; // (*ps).salary = 1200.12;
, ( ):
(, , ) .
1. .. / C++. / .. . , 2002.
2. .. / C++. : / .., .. . , 2002.
3. .. / C++. - : / .., ... , 2002.
4. .. ++ Builder./ ... , 2004.
. 3
.. 4
. 4
.. 4
() . 4
. 5
.. 6
. 7
.. 7
. 8
void. 9
.. 9
.. 11
. 11
. 13
. 15
. 17
-.. 18
- .. 18
. 19
. 19
++. 20
.. 21
"". 21
if 21
switch. 22
. 24
. 24
for 24
. 25
. 25
break. 26
continue. 26
return. 26
.. 26
. 28
. 29
. 30
.. 31
.. 31
.. 31
.. 33
. 37
. 37
.. 38
.. 41
++