1.7.5.
calloc.
a[10] float
float *a;
a=(float*)(calloc(10,sizeof(float));
,
. , , a[n][m],
:
#include
main ()
{ double **a;
int n,m,i;
scanf("%d %d",&n,&m);
a=(double **)calloc(m,sizeof(double *));
for (i=0; i<=m; i++)
a[i]=(double *)calloc(n,sizeof(double));
. . . . . . . . . . . .
}
n,m,l. ,
free.
#include
main ()
{ long ***a;
int n,m,l,i,j;
scanf("%d %d %d",&n,&m,&l);
/* -------- -------- */
a=(long ***)calloc(m,sizeof(long **));
for (i=0; i<=m; i++)
{ a[i]=(long **)calloc(n,sizeof(long *));
for (j=0; i<=l; j++)
a[i][j]=(long *)calloc(l,sizeof(long));
}
. . . . . . . . . . . .
/* --------- ----------*/
for (i=0; i<=m; i++)
{ for (j=0; j<=l; j++)
free (a[i][j]);
free (a[i]);
}
free (a);
}
,
, .
,
.
:
#include
main()
{ int vvod(double ***, long **);
double **a; /* a[n][m] */
long *b; /* b[n] */
vvod (&a,&b);
.. /* vvod , */
.. /* */
..
}
int vvod(double ***a, long **b)
{ int n,m,i,j;
scanf (" %d %d ",&n,&m);
*a=(double **)calloc(n,sizeof(double *));
*b=(long *)calloc(n,sizeof(long));
for (i=0; i<=n; i++)
*a[i]=(double *)calloc(m,sizeof(double));
.....
}
,
.
, ,
.
:
#include
int main()
{ float *q, **b;
int i, j, k, n, m;
scanf("%d %d",&n,&m);
q=(float *)calloc(m,sizeof(float));
/* q */
q[0]=22.3;
q-=5;
/* 5, */
/* n-5 */
q[5]=1.5;
/* */
/* */
q[6]=2.5; /* - */
q[7]=3.5; /* - */
q+=5;
/* 0, */
/* q[0], q[1], q[2] */
/* 1.5, 2.5, 3.5 */
q+=2;
/* -2, */
/* -1, 0 .. */
q[-2]=8.2;
q[-1]=4.5;
q-=2;
/* , */
/* q[0], q[1], q[2], */
/* 8.2, 4.5, 3.5 */
q--;
/* . */
/* */
/* q free(q), - */
/* q , */
/* free(q) - */
/* . */
/* q */
/* */
free(++q);
/* */
/* */
b=(float **)calloc(m,sizeof(float *));
for (i=0; i < m; i++)
b[i]=(float *)calloc(n,sizeof(float));
/* */
/* b[0][0] */
/* , */
/* b[1][1] */
for (i=0; i < m ; i++) --b[i];
b--;
/* */
/* */
for (i=1; i<=m; i++)
for (j=1; j<=n; j++)
b[i][j]=(float)(i+j);
/* */
/* i j, 1 0 */
/* */
for (i=1; i<=m; i++) ++b[i];
b++;
/* */
for (i=0; i < m; i++) free(b[i]);
free(b);
...
...
return 0;
}
, double
double.
:
#include
#include
double cos(double);
double sin(double);
double tan(double);
int main()
{ double (*(*masfun))(double);
double x=0.5, y;
int i;
masfun=(double(*(*))(double))
calloc(3,sizeof(double(*(*))(double)));
masfun[0]=cos;
masfun[1]=sin;
masfun[2]=tan;
for (i=0; i<3; i++);
{ y=masfun[i](x);
printf("\n x=%g y=%g",x,y);
}
return 0;
}
|
|