Dowemo
0 0 0 0

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
//void msg()
//{
//MessageBoxA(0,"内容","标题", 0);
//}
//int add(int num1, int num2)
//{
//return num1 + num2;
//}
//void main()
//{
//msg();
//printf("%dn", add(1, 2));
//printf("%x,%xn", add, msg);//函数名就是函数的首地址
////设断点,然后 调试->窗口->反汇编->输入地址0x...->回车
////可以查出函数的位置
//
//void(*p)() = msg;//定义函数指针,此时参数为空
//p();
//int(*padd)(int num1, int num2) = add;
//printf("%dn", padd(3, 4));
//
//system("pause");
//}
int num1 = 100;
int num2 = 10;
int maxdata(int num1, int num2)
{
 return num1> num2? num1 : num2;//返回最大值
}
int mindata(int num1, int num2)
{
 return num1> num2? num2 : num1;//返回最小值
}
int equaldata(int num1, int num2)
{
 return num1 + num2;
}
int run(int num1, int num2, int(*p)(int, int))//函数指针的参数名可以省略
{
 return p(num1, num2);
}
void main1()
{
 int number, a = 10, b = 20;
 puts("Please inputs number 1/2/3n");
 scanf_s("%d", &number);
 switch (number)
 {
 case 1:
 printf("最大值为%dn", run(a, b, maxdata));
 break;
 case 2:
 printf("最小值为%dn", run(a, b, mindata));
 break;
 case 3:
 printf("和为%dn", run(a, b, equaldata));
 break;
 default:
 break;
 }
 system("pause");
}
void msg(char *str)//字符串指针,传递一个字符串
{
 MessageBoxA(0,"锄禾日当午,学C真他妈苦n", str, 0);
}
int add(int num1, int num2)
{
 return num1 + num2;
}
void main2()
{
//msg("我屮艸芔茻");
//printf("%xn", msg);
//void(*pmsg)(char *str) = msg;
//pmsg("我c");
 int(*padd)(int num1, int num2) = add;
 printf("%dn", padd(6, 7));
 system("pause");
}




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs