.


:




:

































 

 

 

 


!




, , . .

, . , , : (.), (,), (:), (;) . , , .

. . ASCII, ASCII-.

. . , : - 710, - 810, - 910, - 1010, - 1310 .. 0 - 31, 127.

, 28 = 256. , , 256 :

 

_____ - .

, , ..

, (, , .). :

  1. (,...,z, ,...,Z) (_).
  2. , (0,...,9). .
  3. (,...,z), , (,...,Z). , : name, NaMe, NAME ..
  4. , (, , ..) . , ANSI C 32 ( ++ ). 5, count counter , .

 

2) :

 

, .

 

-. {}.

 

, main().

 

" " -;. .

 

,

( ). .

 

/* - ;

*/ - .

 

, , .

 

:

 

int a; /*

*/

.

 

, //. , // :

float b; //

 

, , main(). main() , .

 

(), . main() , .

 

-:

int main()

void main().

. . . void main() - , , main() .

 

int main() , , . , , .

return 0; //

 

.

 

. , , , , .

 

 

: "Hello, world!".

#include <stdio.h> // -

int main() //

{

printf("Hello, world!"); //

getchar(); //

return 0;

}

 

:

Hello world

 

.

#include <stdio.h>

int main()

{

printf(", !");

getchar();

return 0;

}

 

:

, !

, Microsoft Visual Studio . , , (1251). system("chcp 1251") . system() <stdlib.h>.

 

:

#include <stdio.h>

#include <stdlib.h>

int main()

{

system("chcp 1251"); // 1251

system("cls"); //

printf(", !"); //

getchar();

return 0;

}

:

, !

3)

 

ASCII () 0 127 . , () , ('!', '%', '~' ..). , , - (, , .). ASCII (, ) 128 255. '0' '9' 48 57. , "" . , '0' 48, '5', 53, 53 48, 5. . () 65 (A) 90 (Z), () 97 122.

 

, .. . . , 'a' , , ? : '\n'. , . ( ) , : '\n' ; '\t' ( ); '\r' ( ); '\b' . , , , , , . . , .. - . , , , . : '\\' ; '\'' ; '\"' ( '"'); '\0' , 0 ASCII.

4):

. . :

- ;

- ;

- ;

- ,

, :

- ( );

- ;

- , .

, : , , , , , ( ).

. , , . , , .

: , , , , .

: . -, , NAME1, name 1, Name 1, name_1

: . .1.1

1.1

Eng Eng
har Asm  
Class Break
Double Case
Enum Continue
Float Default
. 1.1      
Int Delete
Long Do
Short Else
Struct For
Union Go to ()
Unsigned If
Void New
Return Switch
Extern Inline
Register Const
Overload Typedef
Auto While
Static Public
             

 

 

: , , , .

. - , 0, . 8 9 . 0X 0x . A F(f), 10 15.

: 0x53=83; 0xF=15; 0xA = 10.

, , (long), (int).

: , , L (l), .

: 12l - ,

0123L - ,

0xaaaal - .

. 1.2.

. , 0xAB01 0x53, , [1].

 

 

1.2

- - --
        0x0
        0x1
        0x2
        0x3
        0x4
        0x5
        0x6
        0x7
        0x8
        0x9
  A     0xA
  B     0xB
  C     0xC
  D     0xD
  E     0xE
  F     0xF

 

A B 0 1

1010 1011 0000 0001 > 1010101100000001=

1 * 215 + 0 * 214 + 1 * 213 + 0 * 212 + 1 * 211 + 0 * 210 + 1 * 29+ 1 * 28 + 1 * 20 = 43777;

0x53 = 01010011 = 0 * 27 + 1 * 26 + 0 * 25 + 1 * 24 + 0 * 23 + 0 * 22 + 1* 21 + 1 * 20 = 83;

, (, x). (). char. , \ .1.3

1.3

\n
\t
\v
\b
\v
. 1.3  
\f
\\
\
0ddd \ddd
0xddd \xddd
\0

\ddd , 1, 2, 3 - , . \xddd , 1, 2, 3 .

( ) .

: 345. = 345

3.14159

2.15 = 210000

.1233 = 123

4037-5 =.04037

. , . char, static. . , , . () \O , . \. , , .

:

A

\*\

. , , , . , . , .

. , .

. : , , .

- , , . , , .

, . , , .

- , - .

 

2: C++. .

1) C++:

, .

, . , display, , PC. , , , . main() display. .

//
#include <iostream.h>
enum disp_type {mono, cga, ega, vga};
class display {
int colors; // enum
disp_type dt; //
public:
void set_colors(int num) {colors = num; }
int get_colors() {return colors;}
void set_type (enum disp_type t) {dt = t; }
enum disp_type get_type() {return dt; }
};
char names [4 ] [5] = {
"mono",
"cga",
"ega",
"vga"
};
int main()
{
display monitors [3];
register int i;
monitors[0].set_type(mono);
monitors[0].set_colors(1);
monitors[1].set_type(cga);
monitors [1].set_colors(4);
monitors[2].set_type(ega);
monitors [2].set_colors(16);
for (1=0; i<3; i++) {
cout << names[monitors[i].get_type()] << " ";
cout << "has " << monitors[i].get_colors();
cout << " colors" << "\n";
}
return 0;
}

:

mono has 1 colors
cga has 4 colors
ega has 16 colors

, , names . , , 0, 1 . . get_type() names, .

, .

 

2

1: C.

" " " ". - , , , - . , , - . , :

  • char - ;
  • int - ;
  • float - ;
  • double - ;
  • void - .

 

, , .

. :

.

.

, .

, .

,

,

.

()

- .

- , .

- ( ), .

- , - , .

, , . . ().

, 32 , a - z, A - Z, 0 - 9 (_). .

, , 32 , 8 . , . , , .

.

int a = 2, b; b = a+3; Int a=2; // int INT a=2;
int a = 2, b; b = A + 3; //
int a = 2; b = a + 3; // b

.

0 2n-1, n- .

-2n-1...+2n-1-1. (0 , 1 ).

:

  unsigned char 0...255 char -128...127
  unsigned short 0...65535 short -32768...32767
  unsigned int int
  unsigned long int long int


. . ( 0) . . , 12345,678

12345,678 = 1,2345678104

0,009876

0,009876 = 9,87610-3

, , 1. (, 0), 0.

, , .

4 .


- , (0 , 1 - ).

- 2, . 2 , , 2 ,

N-1

n - , .

- , 1, 1.

- , .

:

- -
float   30...23 22...0  
double   62...52 51...0  
- long double   78...64 62...0  

, float double . , . , float :

: -178,125 32- ( float).
:
17810 = 101100102.
0,12510 = 0,0012. 178,12510 = 10110010,0012=1,01100100012111
( 7 ).
:

0111111+00000111 = 10000110.

, -178,125

. . char.

: - , .

. .

int n; // n
double a; // a

 

2: C++. .

++ . .

:

& = 2;

2 .

!

int a,b;
int &alt=a; // alt ( a)
alt = b; // a=b;
alt++; // a++;

int *ptr = &a;

:

*ptr == alt; // ,
ptr == &alt; // ,

, , *.

, .

:

const char &new_line='\n';

temp :

char temp = '\n';
const char &new_line = temp;

++ . :

, ;

, .

, :

-, ,

-, , .

. , :

void swap (int *a, int *b) { int temp = *a; *a = *b; *b = temp; } void swap (int &a, int &b) { int temp = a; a = b; b = temp; }
: int x = 10; int y = 5; swap(&x, &y); : int x = 10; int y = 5; swap(x, y);

, :

, , . , , , const. , const .

, ++ , .

void swap (int &, int &);
int main() {
int x=10;
unsigned int y;
y=5;
swap(x, y);
...
}

:

int temp = (int)y;
int &t = temp;
swap(x, t);

swap() x temp. temp , y .

++ , . . ,

, return; .

, return . ( , ).

.

 

 

3:

1: / C.

,
. -.

. stdio.h.

printf() -

scanf() - .

printf() . . ,
.

printf():

printf("", 1, 2,..., n);

:

;

, ;

, .

.

, . '\' .
:

'\n' ;

'\t' ;

'\v' ;

'\b' ;

'\r' ;

'\a' .

, , . '%' :

%d int ;

%u unsigned int;

%x int ;

%o int ;

%hd short ;

%hu unsigned short;

%hx short ;

%ld long int ;

%lu unsigned long int;

%lx long int ;

%f ( float);

%lf ( double);

%e ( float );

%c ;

%s .

int a=5;
float x = 2.78;
printf("\n a=%d", a);
printf("\n x=%f", x);

a=5
x=2.780000

, .

float y=1.2345;
printf("\n y=%10.5f\n", y);


y= 1.23450

10 ; 5 . 10, . .

scanf() , , . .
scanf()

scanf ("C", 1, 2,...);

printf(). '&':

= &

.

#include <stdio.h>
#include <stdlib.h>
int main()
{

float y;

system("chcp 1251");

system("cls");

printf(" y: ");

scanf("%f",&y); // y

printf(" y=%f",y);

getchar(); getchar();

return 0;
}

:

 

2: C++. this

1) C++

. ++ , . ++.

(.). , (>). .

, . P_example ob, P_example. , ob :

//
#include <iostream.h>
class P_example {
int num;
public:
void set_num(int val) {num = val; }
void show_num();
};
void P_example::show_num()
{
cout << num << " \n";
}
int main()
{
P_example ob, *p; //
ob.set_num(1); // ob
ob.show_num();
= &ob; // ob
p->show_num(); // ob
return 0;
}

, ob & , .

, . . , ob P_example. , :

//
#include <iostream.h>
class P_example {
int num;
public:
void set_num(int val) {num = val;}
void show_num();
};
void P_example::show_num()
{
cout << num << "\n";
}
int main()
{
P_example ob[2], *p;
ob[0].set_num(10); //
ob[1].set_num(20);
p = &ob[0]; //
p->show_num(); // ob[0]
++; //
p->show_num(); // ob[1]
--; //
p->show_num(); // b [0]
return 0;
}

10, 20, 10.

 

2) this

, -, , . , this. this -. (- this.) , :

b.f();

f() this, ob.

, - . , :

class cl {
int i;
//...
};

- i 10, :

i = 10;

:

this->i = 10;

, , this, :

#include <iostream.h>
class cl {
int i;
public:
void load_i(int val) { this->i = val; } // , i = val
int get_i() { return this->i; } // , return i
};
int main ()
{
cl o;
o.load_i(100);
cout << o.get_i();
return 0;
}

100.

4

1: C.

" " " ". - , , , - . , , - . , :

  • char - ;
  • int - ;
  • float - ;
  • double - ;
  • void - .

 

, , .

. :

.

.

, .

, .

,

,

.

()

- .

- , .

- ( ), .

- , - , .

, , . . ().

, 32 , a - z, A - Z, 0 - 9 (_). .

, , 32 , 8 . , . , , .

.

int a = 2, b; b = a+3; Int a=2; // int INT a=2;
int a = 2, b; b = A + 3; //
int a = 2; b = a + 3; // b

.

0 2n-1, n- .

-2n-1...+2n-1-1. (0 , 1 ).

:

  unsigned char 0...255 char -128...127
  unsigned short 0...65535 short -32768...32767
  unsigned int int
  unsigned long int long int


. . ( 0) . . , 12345,678

12345,678 = 1,2345678104

0,009876

0,009876 = 9,87610-3

, , 1. (, 0), 0.

, , .

4 .


- , (0 , 1 - ).

- 2, . 2 , , 2 ,

N-1

n - , .

- , 1, 1.

- , .

:

- -
float   30...23 22...0  
double   62...52 51...0  
- long double   78...64 62...0  

, float double . , . , float :

: -178,125 32- ( float).
:
17810 = 101100102.
0,12510 = 0,0012. 178,12510 = 10110010,0012=1,01100100012111
( 7 ).
:

0111111+00000111 = 10000110.

, -178,125

. . char.

: - , .

. .

int n; // n
double a; // a

 

2: C++. .

++ . .

:

& = 2;

2 .





:


: 2017-02-11; !; : 306 |


:

:

, , .
==> ...

1902 - | 1549 -


© 2015-2024 lektsii.org - -

: 0.299 .