HT \t VT \v BS \b CR \r FF \f BEL \a \ \\ ? \? ' \' " \" NUL \0 ooo \ooo hhh \xhhh , . - char. , , ( \) ( \x). . , . : '\6' '\x6' 6 ASCII ack '\60' '\x30' 48 ASCII '0' '\137' '\x05f' 95 ASCII '_' . , (. ). , , . 2.4.4  - , : " " , : ('\0'), 0. sizeof("asdf")==5; " ", "asdf" char[5]. "" char[1]. , s strlen(s)==sizeof(s)-1, strlen() '\0'. \. , " \. '\n', : cout << " \007\n" 7 - ASCII BEL (), \a. "" : " , " , : char alpha[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; , , , alpha : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; '\0', - . , "asdf\000hjkl" strcpy() strlen() "asdf". , . , , . . : char v1[] = "a\x0fah\0129"; // 'a' '\xfa' 'h' '\12' '9' char v2[] = "a\xfah\129"; // 'a' '\xfa' 'h' '\12' '9' char v3[] = "a\xfad\127"; // 'a' '\xfad' '\127' 2.4.5  (0) int. ($$R.4) 0 , , . , 0. , . ( ) " " . 2.5  const, , : const int model = 90; const int v[] = { 1, 2, 3, 4 }; , . - const, , : model = 200; // model++; // , const , , . const: const char* peek(int i) // - { return hidden[i]; } , , , . , , const, (, "" ). - , , . , , ( ) , . , , , . , . , : . "" const, , , : const char* pc = "asdf"; // pc[3] = 'a'; // pc = "ghjk"; // , , * const. : char *const cp = "asdf"; // - cp[3] = 'a'; // cp = "ghjk"; // , , const, : const char *const cpc = "asdf"; // - const cpc[3] = 'a'; // cpc = "ghjk"; // , , . . - const, , : char* strcpy(char* p, const char* q); // *q , .. . , const, , : int a = 1; const int c = 2; const int* p1 = &c; // const int* p2 = &a; // int* p3 = &c; // *p3 = 7; // c 2.5.1.  , , const. : enum { ASM, AUTO, BREAK }; , , . 0 , : const ASM = 0; const AUTO = 1; const BREAK = 2; , : enum keyword { ASM, AUTO, BREAK }; . int. ( int ) . : void f() { keyword k = ASM; int i = ASM; k = i // k = keyword(i); i = k; k = 4; // } , int : int . keyword int, , , . , keyword key; switch (key) { case ASM: // - break; case BREAK: // - break; } , keyword . . : enum int16 { sign=0100000, most_significant=040000, least_significant=1 }; , . 2.6.  , , . : [1] ; [2] . , - . , . , , , , , . , , , . 2.6.1  , ( : , ) char, char ++ , . , , . , , . . , : struct sreg { unsigned enable : 1; unsigned page : 3; unsigned : 1; // unsigned mode : 2; unsigned : 4; // unsigned access : 1; unsigned length : 1; unsigned non_resident : 1; }; DEC PDP11/45 (, ). : , . ($$R.3.6.1 $$R.9.6), . : . sreg : sreg* sr0 = (sreg*)0777572; //... if (sr0->access) { // // sr0->access = 0; } , , . , , . , , , , char! , char int , . - . 2.6.2.  , . , : struct entry { char* name; char type; char* string_value; // type == 's' int int_value; // type == 'i' }; void print_entry(entry* p) { switch(p->type) { case 's': cout << p->string_value; break; case 'i': cout << p->int_value; break; default: cerr << "type corrupted\n"; break; } } string_value int_value , , . , , , : struct entry { char* name; char type; union { char* string_value; // type == 's' int int_value; // type == 'i' }; }; , entry string_value int_value , , entry. , , . , , . , , , . , ($$5.4.6). "" ( , , , ). "" int int* VAX, : struct fudge { union { int i; int* p; }; }; fudge a; a.i = 4095; int* p = a.p; // , .. int int* , , . , ($$3.2.5). , . , fudge, , 0: fudge.p = 0; int i = fudge.i; // i 0 , . , fudge : union fudge { int i; int* p; }; () , . , (. $$5.4.6). 2.7  1. (*1) "Hello, world" (. $$1.3.1). 2. (*1) $$2.1 : , ; , , . 3. (*1) : ; 10 ; 10 ; ; ; -; -; . . 4. (*1.5) , . sizeof. 5. (*1.5) , 'a' 'z' '0' '9' . . , . 6. (*1) 0 . : .$$2.6.2. 7. (*1.5) , double. 8. (*2) : char, short,int,long, float, double, long double, unsigned, char*, int* void*? - ? , int* ? ? , ? 9. (*1) , ++ ? ? - , ? 10. (*1) , . int*. , int&. 11. (*1) str : char str[] = "a short string"; "a short string"? 12. (*1.5) . , . : - , - , . 13. (*1) typedef : unsigned char, unsigned char, , , , 7 , 7 8 7 . 14. (*1) f(char), g(char&) h(const char&) , 'a', 49, 3300, c, uc, sc, c - char, uc - unsigned char sc - signed char. ? ?  * 3.  " " ( ) ++ , , . . , . , . 3.1  . . . , : r=2.5 area=pi*r*r ( pi ). : 2.5 19.635 2.5, - 19.635. : , , . - , , , , , , . , (200 ), , ++. 3.1.1  : : END // END - - END -: PRINT // PRINT - '\n' ';' PRINT - : + - : / * : NUMBER // ++ NAME // ++ '_' NAME = - ( ) , , , . - , *, /, +, - ( ) =. . , . . ++, , . , . (, END, NUMBER, + -) get_token(). expr(), term() prim(). , . , . get_token(). get_token() curr_tok. curr_tok token_value: enum token_value { NAME, NUMBER, END, PLUS='+', MINUS='-', MUL='*', DIV='/', PRINT=';', ASSIGN='=', LP='(', RP=')' }; token_value curr_tok; , get_token() , curr_tok , . . , , . "" . expr() . , : double expr() // { double left = term(); for(;;) // ``'' switch(curr_tok) { case PLUS: get_token(); // '+' left += term(); break; case MINUS: get_token(); // '-' left -= term(); break; default: return left; } } . , , . , 2-3+4 (2-3)+4, . for(;;) - , "". for, while(1). switch , + - , return (default). += -= . : left=left+term() left=left-term(). left+=term() left-=term() , . @ x@=y x=x@y, , x . : + - * / % & | ^ << >> : += -= *= /= %= &= |= ^= <<= >>= , a + =1 (- + =). : % - , &, | ^ - , ; << >> . term() get_token() expr(). 4 . , , . expr(), term(), , , prim(), , , expr(). - , prim() : double expr(); // term() , expr() : double term() // { double left = prim(); for(;;) switch(curr_tok) { case MUL: get_token(); // '*' left *= prim(); break; case DIV: get_token(); // '/' double d = prim(); if (d == 0) return error(" 0"); left /= d; break; default: return left; } } , , , . error() . d , , . . . . , , , . , = , == . prim, , expr term(). , - . : double number_value; char name_string[256]; double prim() // { switch (curr_tok) { case NUMBER: // get_token(); return number_value; case NAME: if (get_token() == ASSIGN) { name* n = insert(name_string); get_token(); n->value = expr(); return n->value; } return look(name_string)->value; case MINUS: // get_token(); return -prim(); case LP: get_token(); double e = expr(); if (curr_tok != RP) return error(" )"); get_token(); return e; case END: return 1; default: return error(" "); } } NUMBER ( ), . get_token() number_value. , , , . . : , ( token_value), ( ) . curr_tok, NUMBER number_value. , , . ($$3.5 [15]). NUMBER number_value, NAME name_string. , - , , , , . . $$3.1.3; , , : struct name { char* string; name* next; double value; }; next , : name* look(const char*); name* insert(const char*); name, -. look() "", . , , . 3.1.2  - . , , "" , . , , , . , . get_token(). , . . . get_token() . , '\n' , . , '\n' , . (, ..). do, while, , do : char ch; do { // '\n' if(!cin.get(ch)) return curr_tok = END; } while (ch!='\n' && isspace(ch)); cin.get(ch) ch. if(!cin.get(ch)) - , cin . END, . ! (NOT) , get() . - isspace() <ctype.h> , ($$10.3.1). , , . , isspace(), . isalpha(), isdigit() isalnum(), get_token(). , . , , . '\n' ';', , : switch (ch) { case ';': case '\n': cin >> ws; // return curr_tok=PRINT; , , , get_token(). ws, <stream.h>, . , get_token(). , , . ('\n' ';') PRINT, curr_tok. : case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': cin.putback(ch); cin >> number_value; return curr_tok=NUMBER; , ,- , ; . >> double, : ( ) cin, number_value. , .. NAME, , : if (isalpha(ch)) { char* p = name_string; *p++ = ch; while (cin.get(ch) && isalnum(ch)) *p++ = ch; cin.putback(ch); *p = 0; return curr_tok=NAME; } name_string , . isalpha() isalnum() <ctype.h>. isalnum(c) , c - , . , , : token_value get_token() { char ch; do { // '\n' if(!cin.get(ch)) return curr_tok = END; } while (ch!='\n' && isspace(ch)); switch (ch) { case ';': case '\n': cin >> ws; // return curr_tok=PRINT; case '*': case '/': case '+': case '-': case '(': case ')': case '=': return curr_tok=token_value(ch); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': cin.putback(ch); cin >> number_value; return curr_tok=NUMBER; default: // NAME, NAME= if (isalpha(ch)) { char* p = name_string; *p++ = ch; while (cin.get(ch) && isalnum(ch)) *p++ = ch; cin.putback(ch); *p = 0; return curr_tok=NAME; } error(" "); return curr_tok=PRINT; } } , token_value ( ). 3.1.3  : name* look(char* p, int ins =0); , , , . =0 , , look() . , look("sqrt2"), look("sqrt2",0), .. , . , : inline name* insert(const char* s) { return look(s,1); } , : struct name { char* string; name* next; double value; }; next . - name: const TBLSZ = 23; name* table[TBLSZ]; , table . look() - (, -, ): ): int ii = 0; // - const char* pp = p; while (*pp) ii = ii<<1 ^ *pp++; if (ii < 0) ii = -ii; ii %= TBLSZ; , ^ (" ") p ii. x^y 1 , x y . ^ ii , ii. : ii <<= 1; ii ^= *pp++; - ^, +. - . if (ii < 0) ii = -ii; ii %= TBLSZ; , ii 0...TBLSZ-1. , % - . look: #include <string.h> name* look(const char* p, int ins =0) { int ii = 0; // - const char* pp = p; while (*pp) ii = ii<<1 ^ *pp++; if (ii < 0) ii = -ii; ii %= TBLSZ; for (name* n=table[ii]; n; n=n->next) // if (strcmp(p,n->string) == 0) return n; if (ins == 0) error(" "); name* nn = new name; // nn->string = new char[strlen(p)+1]; strcpy(nn->string,p); nn->value = 1; nn->next = table[ii]; table[ii] = nn; return nn; } - ii next.