如下的话就表示两个字符串相等了是么?

# include <stdio.h>
# include <string.h>
void check(char *a, char *b, int(*cmp)(const char *, const char *));
void main()
{
char s1[80], s2[80];
int(*p)(const char *, const char *); /* 函数指针 */

p = strcmp; /* 将函数strcmp的地址赋给函数指针p */

printf("输入两个字符串:\n");
gets(s1); /* 输入字符串1 */
gets(s2); /* 输入字符串2 */

check(s1, s2, p); /* 通过指针变量p传递函数strcmp的地址 */
}

void check(char *a, char *b, int(*cmp)(const char *, const char *))
{
printf("测试是否相等\n");
if(!(*cmp)(a, b))
printf("结果:相等\n");
else
printf("结果:不相等\n");
}
就想问:*cmp不是指向strcmp函数么?那么if(!(*cmp)(a, b))应该表示
if((*cmp)(a, b)==0)是么?

郎朗坤
浏览 65回答 2
2回答

手掌心

if(!(*cmp)(a, b)) 就是 if(!strcmp(s1, s2)) 即 strcmp(s1, s2)结果不为0,即s1不等于s2

慕侠2389804

if(!(*cmp)(a, b))与if((*cmp)(a, b)==0)是不一样的。
打开App,查看更多内容
随时随地看视频慕课网APP