.


:




:

































 

 

 

 


( return)




, void, ( ) . return.

:

int fac(int n) {return (n>1)? n*fac(n-1): 1; }

return:

int fac(int n)

{

if (n > 1)

return n*fac(n-1);

else

return 1;

}

, . . .

:

double f()

{

//...

return 1; // double(1)

}

, , . , . :

int* f() {

int local = 1;

//...

return &local; //

}

, :

int& f() {

int local = 1;

//...

return local; //

}

, .

:

int& f() { return 1;} //

: . , , .

:

void error(char* p) { /*... */ }

void (*efct)(char*); //

void f()

{

efct = &error; // efct error

(*efct)("error"); // error efct

}

, , efct, , *efct. () , *, *efct("error"). *efct("error"), . .

, , . .

:

void (*pf)(char*); // void(char*)

void f1(char*); // void(char*)

int f2(char*); // int(char*)

void f3(int*); // void(int*)

void f()

{

pf = &f1; // ok

pf = &f2; // :

pf = &f3; // :

(*pf)("asdf"); // ok

(*pf)(1); // :

int i = (*pf)("qwer"); // : void int"

}

.

, - , --.

:

typedef int (*SIG_TYP)(); //

typedef void (*SIG_ARG_TYP);

SIG_TYP signal(int,SIG_ARG_TYP);

. , *4 . , :

typedef void (*PF)();

PF edit_ops[] = { //

cut, paste, snarf, search

};

PF file_ops[] = { //

open, reshape, close, write

};

, , , (button) :

PF* button2 = edit_ops;

PF* button3 = file_ops;

. , - , , . . () . , 3 2, :

(button2[3])();

- . , . .

, , :

typedef int (*CFT)(char*,char*);

int sort(char* base, unsigned n, int sz, CFT cmp)

{

for (int i=0; iname, Puser(q)->name);

}

int cmp2(char*p, char* q) // dept

{

return Puser(p)->dept-Puser(q)->dept;

}

:

main ()

{

sort((char*)heads,6,sizeof(user),cmp1);

print_id(heads,6); //

cout << "n";

sort((char*)heads,6,sizeof(user),cmp2);

print_id(heads,6); //

}

inline-, , , .


: , . 1010.

: , . , , .

 
 


-
+
-
-
+
+

:

#include <vcl.h>

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#pragma hdrstop

#include <iostream>

#include <iomanip>

using namespace std;

 

#pragma argsused

 

int main(int argc, char* argv[])

{int A[10][10],i,k,z=0,n=1; //

 

srand(time(NULL));

for(i=0;i<10;i++) //

{ cout<<endl;

for(k=0;k<10;k++)

{A[i][k]=(50-(rand()%70));

cout<<setw(4)<<A[i][k];

}}

cout<<endl<<endl;

for(i=0;i<10;i++) //

{

for(k=0;k<10;k++)

{ if ((A[i][k]<A[i-1][k-1])&&(A[i][k]<A[i-1][k])&&(A[i][k]<A[i-1][k+1])&&(A[i][k]<A[i][k+1])&&(A[i][k]<A[i+1][k+1])&&(A[i][k]<A[i+1][k])&&(A[i][k]<A[i+1][k-1])&&(A[i][k]<A[i][k-1])) //

{z=z++;

cout<<"Lokalniy minimum #"<<n<<": "; //

n=n++;

cout<<A[i][k]<<endl;}}}

cout<<endl<<"Kol-vo lokalnih minimumov: "<<z<<endl;

system ("pause");

return 0;

}

1 .

, , , , , .

. , .


1. ++. . . [, 2007] ( , )

2. ++[http://cppstudio.com/uchebniki/yazyk-programmirovaniya-s/prototipy-funkcij-v-s/]

3. C++[http://code-live.ru/post/cpp-functions/]

 





:


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


:

:

, .
==> ...

1672 - | 1535 -


© 2015-2024 lektsii.org - -

: 0.02 .