#include "stdafx.h"
#include <iostream>
using namespace std;
char* func(char* s1,char* s2){
if(strcmp(s1,s2)>=0){
return s1;
}else{
return s2;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char *str1="abcdef"; // char str1[]="abcdef" 正确
char *str2="frhu"; //char str2[]="ccccef";正确
char *longest=func(str1,str2);
cout<<longest<<endl;
system("pause");
return 0;
}
//frhu
//请按任意键继续. . .
/////////函数指针,是指向函数的指针,把函数的地址赋给该指针;
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;
int max(int a,int b){
if(a>b){
return a;
}else{
return b;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int (*pmax)(int ,int);
int x=2,y=3,maxval;
pmax=max;//// int (*pmax)(int ,int);和int max(int a,int b)指向相同的地址,
//所以pmax(x,y);运行的还是int max(int a,int b)
//maxval=pmax(x,y);///正确
maxval=(*pmax)(x,y);///正确
cout<<"最大值:"<<maxval<<endl;
system("pause");
return 0;
}
//最大值:3
//请按任意键继续. . .