1. 函数原型,函数定义,函数调用
2.
a. void igor()
b. float tofu(int x)
c. double mpg(double a,double b)
d. long summation(long ar[],int n)
e. double doctor(const char*str)
f. void ofcourse(boss b)
g string plot(map *m)
3.void (int ar[], int n,int a)
{
for (int i=0;i<n;i++)
ar[i] = a;
}
4. void(int *start, int*end, int a)
{
int *pt;
for (pt = start; pt != end; pt++)
*pt = a;
}
5 double max( const double ar[], int size)
{
double temp = 0;
for(int i = 0; i<size;i++)
{
if (temp < ar[i])
temp = ar[i];
}
return temp;
}
6.
将const限定符用于指针,以防止指向的原始数据被修改。程序传递基本类型(如int或double)时,它将按值传递,以便函数使用副本。这样,原始数据得到保护。
8.
int replace(char *str, char c1, char c2)
{
int count =0;
While(*str != ’\n’)
{
if ((*str)==c1)
{
*str = c2;
count++;}
str++;
}
return count;
}
9. 指向字符串“pizza”第一个字符p的指针; c
10. 传递值就是函数调用时产生一个这个结构对象的副本,并对副本引用或操作;传递地址就是对这个结构本身引用或操作。强者更安全,但当结构对象比较大时,后者效率会更高。
11.
int fun (const char * ch);
void judge(int (*fun) (const char *ch))
12
a. void show(applicant a)
{
cout << a.name << endl;
cout << a.credt_ratings[0] << a.credit_ratings[1] << a.credit[2];
}
b.
void show(applicant *a)
{
cout << a->name << endl;
cout << a->credt_ratings[0] << a->credit_ratings[1] << a->credit_ratings[2];
}
13.
void (*p1) (applicant *a) = f1;
const char (*p2) (const applicant *a1, const applicant *a2) = f2;
typedef void (*p_fun1) (applicant *a);
p_fun1 ap[3] ;
typedef const char (*p_fun2) (const applicant *a1, const applicant *a2);
p_fun2 pa[5];