I come, I see, I conquer

                    —Gaius Julius Caesar

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::


1. Write in words the data type of the identifier involved in the following definitions.

(1float (**b)[10];
(
2float *(*b)[10];

(
3float (*b[10])();
(
4float *((*b)[10]);

(
5float (*p)(int);
(
6float (*(*p)(int,int))(int);


答案:
(1) b是一个二级指针,它指向的是一个一维数组的指针,数组的元素都是float。
(2) b是一个指针,它指向一个一维数组,数组元素都是float *。
(3) b是一个数组,b有10个元素,元素都是函数的指针,指向的函数类型是没有参数且返回值类型为float的函数。
(4) 与(2)是一样的,b是一维数组的指针。
(5) 函数指针。
(6) p是一个函数的指针,指向的函数的类型是有两个int参数并且返回一个函数指针的函数,返回的函数指针指向有一个int参数且返回int的函数。


2. Find the defects in each of the following programs.

#include <stdio.h>

int max(int x, int y)
{
    
return x > y ? x : y;
}

int main()
{
    
int max(x, y);
    
int *= &max;

    
int x = (*p)((*p)(1,2),3);

    printf(
"Among 1, 2, 3, the maximal integer is: %d \n", x);

    
return 0;
}



正确的程序如下:

#include <stdio.h>

int max(int x, int y)
{
    
return x > y ? x : y;
}

int main()
{
    
int max(intint); //Error #1
    int (*p)(intint= &max; //Error #2

    
int x = (*p)((*p)(1,2),3);

    printf(
"Among 1, 2, 3, the maximal integer is: %d \n", x);

    
return 0;
}
posted on 2008-10-12 10:26  jcsu  阅读(465)  评论(0编辑  收藏  举报