. - , , . , . , i x, . :: , : int x; void f2() { int x = 1; // x ::x = 2; // x } . ( , - . $$R.3.2). , , . : int x; void f3() { int x = x; // } . , : " ". , ::, . : int x = 11; void f4() // { int y = x; // x int x = 22; y = x; // x } y x, .. 11, x, .. 22. , : void f5(int x) { int x; // } x . , . 2.1.2  "", , . "", , *p[a+10]=7. , " ". : " - , , " ($$R.3.7). (lvalue - left value, .. ) ", ". (. $$2.5). , const, . 2.1.3  , , . , ( ) . static, . , " " , : int a = 1; void f() { int b = 1; // f() static int c = a; // cout << " a = " << a++ << " b = " << b++ << " c = " << c++ << '\n'; } int main() { while (a < 4) f(); } : a = 1 b = 1 c = 1 a = 2 b = 1 c = 2 a = 3 b = 1 c = 3 '' #include <iostream>. , . "++" , . . a++ : 1 a. static, , (#2.4.5). new delete, , (. $$3.2.6). 2.2  () . . _. ++ . , (, ), , , . , , ++, , . (, $ ) . ++ (. $$R.2.4), : hello this_is_a_most_unusially_long_name DEFINED foO bAr u_name HorseSense var0 var1 CLASS _class ___ , : 012 a fool $sys class 3var pay.due foo~bar .name if , Count count - . , , . , , , , . , , var10 - , var 10. elseif - (), else if. 2.3  () . , (.. , ), . : int error_number; float real(complex* p); error_number int (), , . real , complex. , . , int complex, . , . , sizeof ( , ) new ( ). : int main() { int* p = new int; cout << "sizeof(int) = " << sizeof(int) '\n'; } ($$3.2.5), : float f; char* p; //... long ll = long(p); // p long int i = int(f); // f int 2.3.1  ++ . : char short int int long int . : float double long double , , ..: unsigned char unsigned short int unsigned int unsigned long int , : signed char signed short int signed int signed long int int , signed . signed char : 3 - unsigned char, signed char char (. $$R.3.6.1). ( ) int , .. long long int, unsigned - unsigned int. , , , int. , int: const a = 1; // , static x; // , int, . (. $$R.7.1). char. 8 . ++ char, sizeof(char) 1. char . , unsigned char , , , . , unsigned char char . , signed char . , , . , . , , (, int) . , , , . : 1==sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long) sizeof(float)<=sizeof(double)<=sizeof(long double) sizeof(I)==sizeof(signed I)==sizeof(unsigned I) I char, short, int long. , char , 8 , short - , 16 long - , 32 . char . , char 0..127. - . , . , , unsigned int, , . unsigned, , , , : unsigned surprise = -1; ( ). 2.3.2  . , , , . $$R.4 $$R.5.4. - , . , , . , , , 8 : int i1 = 256+255; char ch = i1 // ch == 255 int i2 = ch; // i2 == ? ch=i1 ( !), i2, ch " ", .. 8 . i2? DEC VAX, char , -1, Motorola 68K, char - , 255. ++ , , . 2.3.3  ( ) , : * & [] () , , . : int* a; float v[10]; char* p[20]; // 20 void f(int); struct str { short length; char* p; }; $$R.8. , , : int v[10]; // i = v[3]; // int* p; // i = *p; // , , , * & , [] () - . , , . , [] , *, : int* v[10]; // int (*p)[10]; // , . . . , : int x, y; // int x; int y; , , ( ). : int* p, y; // int* p; int y; int* y; int x, *p; // int x; int* p; int v[10], *p; // int v[10]; int* p; , , , . 2.3.4 void void , . void . , . void f(); // f void* pv; // void*. , void* (). , void*. , . void* , . . , . : void* malloc(unsigned size); void free(void*); void f() // { int* pi = (int*)malloc(10*sizeof(int)); char* pc = (char*)malloc(10); //... free(pi); free(pc); } : () - , pi void*, malloc(), int. ; $$3.2.6. 2.3.5  T T T*. , T* T. , , : int* pi; char** cpp; // char int (*vp)[10]; // 10 int (*fp)(char, char*); // // char char*, int - (), .. , . . * . : char c1 = 'a'; char* p = &c1; // p c1 char c2 = *p; // c2 = 'a' , p,- c1, , c1, 'a'. c2 *p 'a'. . , , ( ): int strlen(char* p) { int i = 0; while (*p++) i++; return i; } -: , . int strlen(char* p) { char* q = p; while (*q++) ; return q-p-1; } ; $$4.6.9 2.3.6  T T[size] " size T". 0 size-1. : float v[3]; // : // v[0], v[1], v[2] int a[2][5]; // , char* vpc; // 32 , : extern "C" int strlen(const char*); // <string.h> char alpha[] = "abcdefghijklmnopqrstuvwxyz"; main() { int sz = strlen(alpha); for (int i=0; i<sz; i++) { char ch = alpha[i]; cout << '\''<< ch << '\'' << " = " <<int(ch) << " = 0" << oct(ch) << " = 0x" << hex(ch) << '\n'; } } oct() hex() . <iostream.h>. alpha strlen() <string.h>, alpha ($$2.4.4). ASCII : 'a' = 97 = 0141 = 0x61 'b' = 98 = 0142 = 0x62 'c' = 99 = 0143 = 0x63 ... , alpha: , , . - , , . , , : char v[9]; v = "a string"; // (. $$7.10). , ; . , . : int v1[] = { 1, 2, 3, 4 }; int v2[] = { 'a', 'b', 'c', 'd' }; char v3[] = { 1, 2, 3, 4 }; char v4[] = { 'a', 'b', 'c', 'd' }; v3 v4 - ( ) ; v4 , . char . . , , . - (. $$3.2.2). : int bad[5,2]; // int v[5][2]; int bad = v[4,1]; // int good = v[4][1]; // , , , 5 char: char v[2][5]; , - . char v[2][5] = { { 'a', 'b', 'c', 'd', 'e' }, { '0', '1', '2', '3', '4' } }; main() { for (int i = 0; i<2; i++) { for (int j = 0; j<5; j++) cout << "v[" << i << "][" << j << "]=" << v[i][j] << " "; cout << '\n'; } } : v[0][0]=a v[0][1]=b v[0][2]=c v[0][3]=d v[0][4]=e v[1][0]=0 v[1][1]=1 v[1][2]=2 v[1][3]=3 v[1][4]=4 2.3.7  ++ . , alpha : int main() { char alpha[] = "abcdefghijklmnopqrstuvwxyz"; char* p = alpha; char ch; while (ch = *p++) cout << ch << " = " << int (ch) << " = 0" << oct(ch) << '\n'; } p : char* p = &alpha[0]; -, . , strlen : void f() { extern "C" int strlen(const char*); // <string.h> char v[] = "Annemarie"; char* p = v; strlen(p); strlen(v); } , : , v ($$4.6.3). +, -, ++ -- . p T*, , p T. p+1 , p-1 - . , () p+1 sizeof(T) , p. main() { char cv[10]; int iv[10]; char* pc = cv; int* pi = iv; cout << "char* " << long(pc+1)-long(pc) << '\n'; cout << "int* " << long(pi+1)-long(pi) << '\n'; } , (Maccintosh) , - , : char* 1 int* 4 long ($$3.2.5). "" int, ++ int (.. sizeof(int)<sizeof(char*)). , ( ). () , . ; . , , ( ), . : void f() { int v1[10]; int v2[10]; int i = &v1[5]-&v1[3]; // 2 i = &v1[5]-&v2[3]; // int* p = v2+2; // p == &v2[2] p = v2-2; // *p } , . , ++ . , . , , . (. $$1.4.3). 2.3.8  , () . : struct address { char* name; // "Jim Dandy" long number; // 61 char* street; // "South Street" char* town; // "New Providence" char* state[2]; // 'N' 'J' int zip; // 7974 }; , address, . , , . : ++ , , . address , , . () . : address jd; jd.name = "Jim Dandy"; jd.number = 61; struct , . : address jd = { "Jim Dandy", 61, "South Street", "New Providence", {'N','J'}, 7974 }; ($$5.2.4). , jd.state "NJ". '\0', "NJ" , , jd.state. c , ->. : void print_addr(address* p) { cout << p->name << '\n' << p->number << ' ' << p->street << '\n' << p->town << '\n' << p->state[0] << p->state[1] << ' ' << p->zip << '\n'; } , . : address current; address set_current(address next) { address prev = current; current = next; return prev; } , , , (== !=), . (. 7). . , , ( , ). - . "" . , sizeof(address) 24, 22, . , , , . : struct link{ link* previous; link* successor; }; , . struct no_good { no_good member; }; ( no_good). ( ) , . : struct list; // struct link { link* pre; link* suc; list* member_of; }; struct list { link* head; }; list, link . , , . : class S; // 'S' - extern S a; S f(); void g(S); , S : void h() { S a; // : S - f(); // : S - g(a); // : S - } 2.3.9  , . , : struct s1 { int a; }; struct s2 { int a; }; : s1 x; s2 y = x; // : , , : s1 x; int i = x; // : , , , , . , typedef, , . : typedef char* Pchar; Pchar p1, p2; char* p3 = p1; . 2.3.10  . , (.$$7). X& X. : int i = 1; int& r = i; // r i int x = r; // x = 1 r = 2; // i = 2; , .. , . , . , , , int ii = 0; int& rr = ii; rr++; // ii 1 ++ , rr++ rr; ++ , .. ii. , : , . , rr, &rr. , . , (.. , ; . $$R.3.7). T . , &T , T. : [1] -, , (.$$R.8.4.3); [2] ; [3] , . : double& dr = 1; // : const double& cdr = 1; // : double* cdrp; // , double temp; temp = double(1); cdrp = &temp; : , , . , . (.$$R.6.3). , . : void incr(int& aa) { aa++; } void f() { int x = 1; incr(x); // x = 2 } , , incr aa x. , , , . , , : int next(int p) { return p+1; } void inc(int* p) { (*p)++; } void g() { int x = 1; x = next(x); // x = 2 inc(&x); // x = 3 } , , , . . . pair: struct pair { char* name; // int val; // }; , . find(), , . pair (: ). - . , , : const int large = 1024; static pair vec[large+1]; pair* find(const char* p) /* // "pair": // p, , "pair", // "pair" */ { for (int i=0; vec[i].name; i++) if (strcmp(p,vec[i].name)==0) return &vec[i]; if (i == large) return &vec[large-1]; return &vec[i]; } value(), , ( ): int& value(const char* p) { pair* res = find(p); if (res->name == 0) { // , // res->name = new char[strlen(p)+1]; strcpy(res->name,p); res->val = 0; // 0 } return res->val; } () value() , ( ) . , , : const int MAX = 256; // main() // { char buf[MAX]; while (cin>>buf) value(buf)++; for (int i=0; vec[i].name; i++) cout << vec[i].name << ": " << vec [i].val<< '\n'; } while cin buf (. 10), , , . vec find(). for cin . aa bb bb aa aa bb aa aa : aa: 5 bb: 3 [] ($$8.8) . 2.4  ++ : , . , (0) , char[]. . - , . ++ : (1) const , ; (2) ; (3) . 2.4.1  : , , . : 0 1234 976 12345678901234567890 int, , int, long. , . , , x (0x), ( 16), , , , ( 8). : 0 02 077 0123 : 0, 2, 63, 83. : 0x0 0x2 0x3f 0x53 a, b, c, d, e f 10, 11, 12, 13, 14 15, . , . , , int 16- , 0xffff -1. , 65535. U unsigned. , L long. : void f(int); void f(unsigned int); void f(long int); void g() { f(3); // f(int) f(3U); // f(unsigned int) f(3L); // f(long int) } 2.4.2  double. , , . : 1.23 .23 0.23 1. 1.0 1.2e10 1.23e-15 , . , 65.43 e-21 , : 65.43 e - 21 . float, , f: 3.14159265f 2.0f 2.997925f 2.4.3  , , , 'a' '0'. , , , . , , . , , ASCII, '0' 48, EBCDIC, 240. . , , : NL(LF) \n