#include<stdlib.h>
#include<string>
#include<math.h>
#include<iostream>
using namespace std;
char *str(char *a , char *b);
int main()
{
char str1[] = "Hello ";
char str2[] = "Welcome C++";
char *max = 0;
cout<<str(str1 , str2)<<endl;
// int m = strlen(str1) - strlen(str2);
// cout<<max<<(strlen(str1) - strlen(str2))<<endl; //为什么此处相减为正数,
//因为原型strlen()返回的是一个无符号类型的数,不能表示负数!!
system("pause");
}
char *str(char *a , char *b)
{
return ( strlen(a) > strlen(b) ? a : b); //返回的为较大的字符串
// ?前边若为非零,计算值为 a,反之为 b;
}
/*总结:指针函数
数据类型 *函数名(参数表···)
1.其中数据类型为返回的指针所指向的数据类型!
2.指针型函数返回的为一个指针(地址)!!*/
*/
//******************************(8.03-10-05)**指向函数的指针***************************
/*
#include<stdlib.h>
#include<string>
#include<math.h>
#include<iostream>
int max(int a , int b);
using namespace std;
int main()
{
int (*p)(int a , int b); //定义了一个指针指向函数,以后再用到这个函数
的时候可以调用这个指针!
p = max;
cout<<(*p)(12 , 465)<<endl;
system("pause");
}
int max(int a , int b)
{
return ( (a > b) ? a : b );
}
/*总结:
1.注意函数指针的定义形式:
int (*p)(int a , int b) (*指针名)要用()括号括起来!,这是与返回值为指针的函
数唯一不同的地方,但是本质却一点不同!*/
学习指针型函数和指向函数的指针
最新推荐文章于 2022-06-29 14:56:31 发布