Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9565
  • 博文数量: 8
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-22 11:07
文章分类
文章存档

2010年(8)

我的朋友
最近访客

分类: C/C++

2010-07-22 13:46:06

再给出常用的C变量的定义方式:
a) 一个整型数(An integer)
b) 一个指向整型数的指针(A pointer to an integer)
c) 一个指向指针的的指针,它指向的指针是指向一个整型数(A pointer to a pointer to an integer)
d) 一个有10个整型数的数组(An array of 10 integers)
e) 一个有10个指针的数组,该指针是指向一个整型数的(An array of 10 pointers to integers)
f) 一个指向有10个整型数数组的指针(A pointer to an array of 10 integers)
g) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数(A pointer to a function that takes an integer as an argument and returns an integer)
h) 一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数( An array of ten pointers to functions that take an integer argument and return an

integer )

答 案是:
a) int a; // An integer
b) int *a; // A pointer to an integer
c) int **a; // A pointer to a pointer to an integer
d) int a[10]; // An array of 10 integers
e) int *a[10]; // An array of 10 pointers to integers
f) int (*a)[10]; // A pointer to an array of 10 integers
g) int (*a)(int); // A pointer to a function a that takes an integer argument and returns an integer
h) int (*a[10])(int); // An array of 10 pointers to functions that take an integer argument and return an integer



Source Code:

#include
#include

typedef struct node
{
    char ch;
    struct node *next;
}ListTable,*ListT;

ListT NewHead(void);//生成一个头结点的链表
ListT ReverseList(ListT list);//将链表逆序
void DisplayList(ListT list);//输出链表
void AddNode(ListT list,int n);//增加节点

int main()
{
    ListT list;
    list = NewHead();
    AddNode(list,26);
    DisplayList(list);
    ReverseList(list);
    DisplayList(list);
    return 0;
   
}

ListT NewHead(void)
{
    ListT head;
    head = (ListT) malloc (sizeof(ListTable));
    head->next = NULL;
   
    return head;
}
void DisplayList(ListT list)
{
    while(list->next != NULL)
    {
        printf("%c ",list->next->ch);
        list = list->next;
    }
    printf("\n");
}


ListADT ReverseList(ListT list)
{
    ListT pre,current,hold;
    pre = NULL;
    current = list->next;
    while(current != NULL)
    {
        hold = current->next;
        current->next = pre;
        pre = current;
        current = hold;
    }
    list->next = pre;
}
void AddNode(ListT list,int n)
{
    int i;
    ListT newlist;
    for(i = 0; i < n; i++)
    {
        newlist = (ListT)malloc(sizeof(ListTable));
        newlist->ch = 'A'+i;
        newlist->next = NULL;
        list->next = newlist;
        list = newlist;
    }

}

阅读(377) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~