//#include <processenv.h>
void test1();
void testEnum();
void valuePoiner();
void funcPointer();
void callFuncPointer(void*(*callback)(int));
int callbackMethod(int arg);
extern void write_extern() {
printf(" write_extern");
};
enum WEEK {
MON = 1, TUE, WED, THU, FRI, SAT, SUN
};
enum PLAYMODE {
LOOP_PLAY, ORDER_PLAY, SINGLE_LOOP, LIST_PLAY, RANDOM_PLAY
};
int main() {
valuePoiner();
funcPointer();
callFuncPointer(callbackMethod);
// testEnum();
// test1();
}
void callFuncPointer(void* (*callback)(int)) {//*在某个值的左边表示取值,在右边表示是声明指针。
int values[]={6,58,7,1,15};
int index;
for(index=0;index<5;index++){
printf("指针方式取值 %d\n",*(values+index));
// printf("指针方式取值 %d\n",*(values++));//会修改指针,不太推荐使用
printf("错误的指针方式取值 %d\n",*(values)+index);//这种方式取值错误,还是基于index的值 的递增而不是指针的递增。
printf("通过数组访问值:%d\n",values[index]);
// =(*(value)+index)+callback(index);
printf("current idnex\n %d",index);
// *(values+index)=1;//修改数组元素
// printf("修改之后:%d\n",*(values+index));
*(values+index)= *(values+index)+callback(index);
printf("调用之后的值:%d\n",*(values+index));
printf("\n\t\t\n");
}
// callFuncPointer(2);
}
int callbackMethod(int value) {
int randomvalue=rand()%100+1;//1-100随机
printf("[回调调用]随机值: %d,传递过来的值%d\n ",randomvalue,value);
return randomvalue+value;
}