0
0
0
1. 云栖社区>
2. 博客>
3. 正文

## 最新作的关于指针，函数指针，线性表的练习存档

~~~~~~~~

#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 20
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0

void MyFun1(int x);
void MyFun2(int x);
void MyFun3(int x);
typedef void (*FunType)(int );
void CallMyFun(FunType fp,int x);

typedef int ElemType;
typedef int Status;

typedef struct
{
ElemType data[MAXSIZE];
int length;
}SqList;

SqList Init()
{
SqList L;
L.length = 0;
return L;
}

SqList Create(SqList L)
{
int i;
for (i=0;i<15;i++)
{
L.data[i] = i;
L.length++;
}
return L;
}

Status GetElem(SqList L,int i,ElemType *e)
{
if (L.length == 0 || i < 1 || i > L.length)
return ERROR;
*e = L.data[i-1];

return OK;
}

int main(void)
{
SqList nmList;
int element;
int j=10;
nmList = Init();

nmList = Create(nmList);

int i;
for(i=0;i < nmList.length;i++)
{
printf("%d\t==%d==\n",i,nmList.data[i]);
}
printf("\n");
GetElem(nmList,j,&element);
printf("the %d element value is:%d\n",j,element);
printf("\n");

int k = 5;
printf("k's right value is :%d\n",k);

int* pi;
pi = &k;
printf("pi's left value is :%x\n",pi);

CallMyFun(MyFun1,10);
CallMyFun(MyFun2,20);
CallMyFun(MyFun3,30);

system("pause");
}

void CallMyFun(FunType fp,int x)
{
fp(x);
}

void MyFun1(int x)
{
printf("MyFun1\n",x);
}

void MyFun2(int x)
{
printf("MyFun2%d\n",x);
}

void MyFun3(int x)
{
printf("MyFun3%d\n",x);
}

+ 关注