strcmp(). , , . name new (. $$3.2.6), . , , . . strlen() , , new , strcpy() . <string.h>: extern int strlen(const char*); extern int strcmp(const char*, const char*); extern char* strcpy(char*, const char*); 3.1.4  , . error , : int no_of_errors; double error(const char* s) { cerr << "error: " << s << "\n"; no_of_errors++; return 1; } cerr . error() , , , . , , . . get_token() , error() . . , . exit(), ($$10.5.1) , . - abort(), ( ). . , (.$$9), 200 . 3.1.5  , , . main(): int main() { // : insert("pi")->value = 3.1415926535897932385; insert("e")->value = 2.7182818284590452354; while (cin) { get_token(); if (curr_tok == END) break; if (curr_tok == PRINT) continue; cout << expr() << '\n'; } return no_of_errors; } , main() , , , . . , . main . : cout << expr() << '\n'; cin , - , END , get_token() . break switch (.. for, while do). PRINT (.. '\n' ';') expr() . continue , : while (cin) { // ... if (curr_tok == PRINT) continue; cout << expr() << "\n"; } : while (cin) { // ... if (curr_tok == PRINT) goto end_of_loop; cout << expr() << "\n"; end_of_loop: ; } $$R.6 3.1.6  , , , , . , . , . , main(). main() : ( argc) ( argv). - , argv char*[argc+1]. ( , ) argv[0], argc . , dc 150/1.1934 : argc 2 argv[0] "dc" argv[1] "150/1.1934" argv[2] 0 ; , , . , ($$10.5.2). , cin , , : int main(int argc, char* argv[]) { switch(argc) { case 1: // break; case 2: // cin = *new istream(argv[1],strlen(argv[1])); break; default: error(" "); return 1; } // main } istrstream - istream, , . istrstream <strstream.h>, <iostream.h>. , main() switch. main() , . , , : dc "rate=1.1934;150/rate;19.75/rate;217/rate" , ';' UNIX . . 3.2  ++ $$R.7. . . . class_name , member - , object - , , pointer - , , expr - , lvalue () - , . (type) ( *, () ..). , . " ", - " ". , a=b=c a=(b=c), a+b+c (a+b)+c, *p++ *(p++), (*p)++. ____________________________________________________________ ++ ============================================================ :: class_name :: member :: :: name ____________________________________________________________ . object . member -> pointer -> member [] pointer [ expr ] () expr ( expr_list ) () type ( expr_list ) sizeof sizeof expr sizeof sizeof ( type ) ____________________________________________________________ ++ lvalue ++ ++ ++ lvalue -- lvalue -- -- -- lvalue ~ ~ expr ! ! expr - - expr + + expr & & lvalue * * expr new () new type delete () delete pointer delete[] delete[] pointer () () ( type ) expr ____________________________________________________________ . * object . pointer-to-member ->* pointer -> pointer-to-member ____________________________________________________________ * expr * expr / expr / expr % expr % expr ____________________________________________________________ + () expr + expr - () expr - expr ____________________________________________________________ , , . " ". , a+b*c a+(b*c), * , +; a+b-c (a+b)-c, + - , + - " ". ____________________________________________________________ ++ () ============================================================ << expr << expr >> expr >> expr ____________________________________________________________ < expr < expr <= expr <= expr > expr > expr >= expr >= expr ____________________________________________________________ == expr == expr != expr != expr ____________________________________________________________ & expr & expr ____________________________________________________________ ^ expr ^ expr ____________________________________________________________ | expr | expr ____________________________________________________________ && expr && expr ____________________________________________________________ || expr || expr ____________________________________________________________ ? : expr? expr : expr ____________________________________________________________ = lvalue = expr *= lvalue *= expr /= lvalue /= expr %= lvalue %= expr += lvalue += expr -= lvalue -= expr <<= lvalue <<= expr >>= lvalue >>= expr &= lvalue &= expr |= lvalue |= expr ^= lvalue ^= expr ____________________________________________________________ () expr , expr ____________________________________________________________ 3.2.1  ++ , . , , , . , , , " " (.. ). , if (i<=0 || max<i) // ... : " i , max i". , if ( (i<=0) || (max<i) ) // ... , if (i <= (0||max) < i) // ... , , , , : if ( (i<=0) || (max<i) ) // ... . , , , . , , , . , "" . , if (i&mask == 0) // ! & == i (i&mask), 0. == , &, i&(mask==0). : if ((i&mask) == 0) // ... , , : if (0 <= a <= 99) // ... , (0<=a)<=99, 0, 1, a (, , a 1). , a 0...99, : if (0<=a && a<=99) // ... , == () = (): if (a = 7) // : // ... , "=" "". . 3.2.2  , , . : int i = 1; v[i] = i++; v[1]=1, v[2]=1. , . , . && || , , . , b=(a=2,a+1) b 3. || $$3.2.1, && $$3.3.1. , , . : f1(v[i],i++); // f2( (v[i],i++) ) // f1 : v[i] i++, . - . . f2 , , : (v[i], i++). i++. . , a*(b/c) (a*b)/c ( - ). , a*(b/c) (a*b)/ . 3.2.3  ++ . ++lvalue lvalue+=1, , lvalue=lvalue+1 , lvalue . , , . (--). ++ -- . ++x (. . 1) x. , y=++x y=(x+=1). , x++ x. , y=x++ y=(t=x,x+=1,t), t - , x. , 1 1 , , . , p++ . p T* : long(p+1) == long(p) + sizeof(T); . , , , : inline void cpy(char* p, const char* q) { while (*p++ = *q++) ; } ++ ( ) , - , . while (*p++ = *q++) ; , . , C C++ . : int length = strlen(q) for (int i = 0; i<=length; i++) p[i] = q[i]; : ; - ; , , . : for (int i = 0; q[i] !=0 ; i++) p[i] = q[i]; p[i] = 0; // p q - , i, : while (*q !=0) { *p = *q; p++; // q++; // } *p = 0; // , , : while (*q != 0) { *p++ = *q++; } *p = 0; // , *p++ = *q++ *q. , : while ((*p++ = *q++) != 0) { } , *q , *q *p, . , , , , "!= 0" , .. . , : while (*p++ = *q++) ; , ? ++ ! ? strlen(), . , , . <string.h>: int strcpy(char*, const char*); 3.2.4  & | ^ ~ >> << , char, short, int, long . . ( ). , . & , | , ^ . . , <iostream.h>: class ios { public: enum io_state { goodbit=0, eofbit=1, failbit=2, badbit=4 }; // ... }; : cout.state = ios::goodbit; ios , io_state ios, , goodbit. : if (cout.state&(ios::badbit|ios::failbit)) // , & , "|". , , : cin.state |= ios::eofbit; |= , (.. state==ios::badbit), cin.state =ios::eofbit; . : ios::io_state diff = cin.state^cout.state; , io_state, , . , , , - , . , ($$R.9.6) , . . , 16 32- : unsigned short middle(int a) { return (a>>8)&0xffff; } : && || ! 0 1, if, while for ($$3.3.1). , !0 ( ) 1, ~0 ( ) " ", -1 . 3.2.5  . , . : float r = float(1); 1 1.0f. , ( ). : , , , (double)a , , double(a). , . , , char* p = (char*)0777; : typedef char* Pchar; char* p = Pchar(0777); , . : Pname n2 = Pbase(n1->tp)->b_name; // Pname n3 = ((Pbase)n2->tp)->b_name; // -> , , : ((Pbase)(n2->tp))->b_name . , any_type* p = (any_type*)&some_object; (some_object) p (any_type). , some_object any_type, . , . , , , , . , , , . , , , , , (struct) (. $$2.6.1). , , , . : int i = 1; char* pc = "asdf"; int* pi = &i; i = (int)pc; pc = (char*)i; // : pc . // sizeof(int) // , sizeof(char*) pi = (int*)pc; pc = (char*)pi; // : pc // char* // , int* , . . , . , ( ) void*, void* . ++ , ( ) . , . 3.2.6  , (.$$2.1.3). . , , , , . , , , . , , , . new, delete . , new, , . , , . , . , . : struct enode { token_value oper; enode* left; enode* right; }; enode* expr() { enode* left = term(); for(;;) switch(curr_tok) { case PLUS: case MINUS: get_token(); enode* n = new enode; n->oper = curr_tok; n->left = left; n->right = term(); left = n; break; default: return left; } } , : void generate(enode* n) { switch (n->oper) { case PLUS: // delete n; } } , new, , , delete. , , new. " ", , , new . delete , new, . delete . new , : char* save_string(const char* p) { char* s = new char[strlen(p)+1]; strcpy(s,p); return s; } , , new, delete . : int main(int argc, char* argv[]) { if (argc < 2) exit(1); char* p = save_string(arg[1]); delete[] p; } , , new, , (, ). delete , delete[] . ($$R.5.3.3-4): void* operator new(size_t); void operator delete(void*); size_t - , <stddef.h>. operator new() . , new ? , . , : char* p = new char [100000000]; . new , , set_new_handler() <new.h>. , : #include <iostream.h> #include <new.h> #include <stdlib.h> void out_of_store() { cerr << "operator new failed: out of store\n"; exit(1); } int main() { set_new_handler(&out_of_store); char* p = new char[100000000]; cout << "done, p = " << long(p) << '\n'; } , "done", : operator new failed: out of store // new : new_handler , . new delete (, , operator new operator delete), new_handler new. , " ", delete . , , . new 0, . new_handler . , : #include <stream.h> main() { char* p = new char[100000000]; cout << "done, p = " << long(p) << '\n'; } done, p = 0 , ! , , new_handler, : . new ( ; .$$R.5.5.6). 3.3  ++ $$R.6. . . ------------------------------------------------------------------ ------------------------------------------------------------------ : { - opt } opt ; if ( ) if ( ) else switch ( ) while ( ) do while ( ) for (--for opt; opt) case - : default : break ; continue ; return opt ; goto ; : -: - --for: opt ; ---------------------------------------------------------------------- , , ( ). 3.3.1  if switch: if ( ) if ( ) else switch ( ) ++ ( , ). : == != < > <= >= 1, , 0 . TRUE 1 FALSE 0. if, , , ( ). , . a , if (a) // ... if (a != 0) ... && || ! . && || , . , if (p && l<p->count) // ... p, , l<p->count. if . , if (a <= b) max = b; else max = a; max = (a<=b) ? b : a; , , . (switch) if. , switch (val) { case 1: f(); break; case 2: g(); break; default: h(); break; } : if (val == 1) f(); else if (val == 2) g(); else h(); , , : val . , , . - , , , . , switch (val) { // case 1: cout << "case 1\n"; case 2: cout << "case 2\n"; default: cout << "default: case not found\n"; } val==1 : case 1 case 2 default: case not found , . . break, return goto. : switch (val) { // case 0: cout << "case 0\n"; case1: case 1: cout << "case 1\n"; return; case 2: cout << "case 2\n"; goto case1; default: cout << "default: case not found\n"; return; } val 2 : case 2 case 1 , goto: goto case 2; // 3.3.2 goto goto - ++: goto ; : , , , ++ , , .. . , goto . , goto , . - - . , goto . - . , break . : void f() { int i; int j; for ( i = 0; i < n; i++) for (j = 0; j<m; j++) if (nm[i][j] == a) goto found; // a // ... found: // nm[i][j] == a } continue, . , $$3.1.5. 3.4  , ,