.


:




:

































 

 

 

 


. Microsoft Visual C++




 

Microsoft Visual C++. , . ++.

 

2.2

ϳ (. 1.3), , , : ++, , , ++: , , , , ++

, - () ѳ . ѳ- , - . , . , ѳ-, .

ѳ :

, h-;

, ѳ-.

".h". ".c" ѳ ".cpp", ".cxx" ".cc" C++. . , C-, . , ѳ- , h- - .

, . . , . #include. .

ѳ. . , . , . , . .

, "Hello, World".

#include <stdio.h> int main() { printf("Hello, World\n"); return 0; }

 

ѳ-. printf ( ). main, ( return 0;), , . , .

C++ , . , ( ) . , , .

, , . ' . :

 

int a[10];char c[256];double d[1000];

 

10 . , ѳ , 0 9. 256 ( 0...255), 1000 ( 0...999). ' , : a[10], c[255], d[123].

, '. ', . ' , . :

int *a, *b, c, d;char *e;void *f;

 

a b int c d int (c d !). 䳿:

1. . , &. , a = &c; a c;

2. ', ; *, . , d = *a; d , a.

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

, , int *(x[10]); " 10 int ";

:

o * . , int *x[10]; " 10 int ". ' x [] ( ), , . . " ", ! , : int (*x)[10]; ' x * ;

o [] ( ') ( ') , , . :

- int f(); f , int;

- int (*f())[10]; f , 10 int;

. . '. , ' . , ( ), ( ), ( ). . , , , . :

void (*a[100])(int x);

a. 100 , , x int, , , void. :

1. a -

2. 100

3.

4. x int,

5. void.

a:

 

void (* a [100])(int x);5) 3) 1) 2) 4)

ѳ . ( ). , , . :

 

char str[10];str[0] = 'e'; str[1] = '2';str[2] = 'e'; str[3] = '4';str[4] = 0;

 

str 10 , 9, . str " e2e4 ". . 5 str 0...4. 5 . , :

char t[] = "abc";

 

t, . ϳ " abc ", t. t , 4 , . , , .

ѳ , . .

³, , , , , ѳ , . , ( ) ѳ; +, += ++. , .

, , .

+, , * / ѳ , %. % , . ³, % ( ), ,

. true false . :

bool res;int x, y;res = (x == y); // true, x y, falseres = (x == x); // trueres = (2 < 1); // false

 

ѳ :

== ,!= ,> , >= ,< , <= .

, ѳ , . :

& ("")| ("")~ ("")^ 2 ( "")

 

( ', && ||, .)

. , ( ).

if (" ") . ³ : " " " ... ". "" :

if () ;

" ... "

 

if () 1;else 2;

- . , " " - . " " if. , , , . , m x y:

 

double x, y, m;...m = x;if (y > x) m = y;

 

" ... " , , , if; else. , :

double x, y, m;...if (x > y) m = x;else m = y;

 

, , , :

 

double x, y, d;...if (d > 1.0) { x /= d; y /= d;}

x y d , d .

ʳ " ... " ( else ). . . : x, y sign(x):

 

sign(x) = -1, x < 0sign(x) = 1, x > 0sign(x) = 0, x = 0

:

 

double x, s;...if (x < 0.0) { s = (-1.0);}else if (x > 0.0) { s = 1.0;}else { s = 0.0;}

 

x < 0.0. , s = (-1.0); x < 0.0. s = 1.0, s = 0.0. Գ .

, (, ). . , .

" " while:

 

while () ;

 

while , . while : . , . ; , , . , . :

int n, p;...p = 1;while (2*p <= n) p *= 2;

 

p , n.

,

 

break;

. : f(x), .

int f(int x); // ...int x;...// f(x) x = 0;while (true) { if (f(x) == 0) { break; // } // x // 0, -1, 1, -2, 2, -3, 3,... if (x >= 0) { x = (-x - 1); } else { x = (-x); }}// : f(x) == 0

 

" while (true) ". " break ".

- , . :

continue;

 

continue, , break, , . , . : n+1 , i = 0, 1,..., n; . n, , . k - 1. :

 

x = t. :

 

double x[100]; // ( 100)int n; // ʳ int k; // double t; // , double L; // L_k(x) t int i;...L = 1.0; // i = 0;while (i <= n) { if (i == k) { ++i; // continue; // k - } // L *= (t - x[i]) / (x[k] - x[i]); ++i; // }// ³ L

 

continue , i = k.

for :

for (; ; ) ;

. . , , . ( ).

, for , while, . , , , ( ).

for:

double a[100]; // a 100 -int n; // a (n <= 100)double sum; // - int i; // ...sum = 0.0;for (i = 0; i < n; ++i) { sum += a[i]; // a[i]}

 

i . i 0. i<n. ++i i . , i 0, 1, 2,..., n-1. i .

, ().





:


: 2016-11-24; !; : 457 |


:

:

- - , .
==> ...

1629 - | 1590 -


© 2015-2024 lektsii.org - -

: 0.045 .