.


:




:

































 

 

 

 





 

. . + + , .

.

(), . .

− , - . . ++ , main − . . . , . , :

 

[ ] _ ([ ])

[throw ()]

{ }

, extern static:

- extern − ( );

- static − , .

, , . , void.

, . . , , ( ).

, . void, , , .

. , :

# include <iostream.h>

int sum (int a, int b); //

int main () {

int a = 2, b = 3, c,d;

c = sum(a, b); //

cin >> d;

cout << sum(c,d);

return 0;

}

int sum (int a, int b) { //

return a+b;

}

, , . . , static.

!!! . , .

, , . . .

return [];

return. void, . return void, , main.

int f1 () {return 1;} //

void f2 () {return 1;} //

. , , , − .

.

. , , .

.

# include <iostream.h>

void f (int i, int *j, int & k);

int main () {

int i = 1, j = 2, k= 3;

cout << "i j k \n";

cout << i << ' '<< j << ' ' << k << '\n';

f(i, &j, k);

cout << i << ' '<< j << ' ' << k << '\n';

return 0;

}

void f(int i, int *j, int &k) {

i ++; (*j)++; k++;

}

 

:

i j k

1 2 3

1 3 4

f (i) . . (j) . (k) .

, const:

int f(const char *a);

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

# include <iostream.h>

int sum (const int *mas, const int n);

int const n = 10;

int main () {

int marks [n] = {3,4,5,4,4};

cout << " " << sum (marks,n);

return 0;

}

int sum (const int *mas, const int n);

// : int sum (int mas [ ], int n);

// int sum (int mas[n], int n);

int s = 0;

for (int i = 0; i<n; i + +;) s +=mas[ i ];

return s;

}

, , . . b , a .

 

 

include <stdio.h>

include <stdlib.h>

int sum (const int *a, const int nstr, const int nstb);

int main () {

int b[2] [2] = {{2,2},{4,3}};

printf (" b: %d \ n",sum (&b[0][0],2,2));

int i, j, nstr, nstb, *a;

printf(" : \n");

scanf("%d%d", &nstr, &nstb);

a=(int *) malloc(nstr*nstb*sizeof(int));

for (i = 0; i<nstr; i++)

for (j = 0; j<nstb; j++) scanf ("%d", &a[i * nstb + j]);

printf(" a: %d \n", sum(a, nstr, nstb));

return 0;

}

int sum (const int *a, const int nstr, const int nstb) {

int i, j, s =0;

for (i = 0; i < nstr; i++)

for (j = 0; j<nstb; j++) s +=a[i*nstb+j];

return s;

}

!!! , , i j: a[i*nstb + j].

− new delete.

# include <iostream.h>

int sum (int **a, const int nstr, const int nstb);

int main() {

int nstr, nstb;

cin >> nstr >> nstb;

int **a, i, j;

a = new int* [nstr];

for (i =0; i<nstr; i++) a[ i ]=new int [nstb];

for (i =0; i<nstr; i++)

for (j =0; j<nstb; j++) cin >> a[ i ][ j ];

cout << sum (a, nstr,nstb);

return 0;

}

int sum (int **a, const int nstr, const int nstb) {

int i, j, s =0;

for (i =0; i<nstr; i++);

for (j =0; j<nstb; j++) s += a[ i ][ j ];

return s;

}

1. , , .

2. , . .





:


: 2016-10-06; !; : 453 |


:

:

, .
==> ...

1563 - | 1332 -


© 2015-2024 lektsii.org - -

: 0.021 .