下列语句中 在字符串s1和s2相等时显示"they are Equal"的是()。A.if(*s1==*s2) puts("they are Eq

计算机 字符串,语句 已帮助 人

下列语句中,在字符串s1和s2相等时显示"they are Equal"的是()。

A.if(*s1==*s2) puts("they are Equal");

B.if(!strcmp(s1,s2)) puts("they are Equal");

C.if(s1==s2) Puts("they are Equal");

D.if(strcmp(s1,s2) ) puts("they are Equal");

热搜:字符串常量是保存在内存中的哪个存储区中的

答案解析

难度★★☆ 搜索
  • 正确答案:B
    解析:字符串比较不能用两个等于号(==)来进行比较,应使用函数strcmp(s1,s2)来比较。函数 strcmp(s1,s2)的功能是:当字符串s1和s2相等时,返回值为0。因此,当表达式!strcmp(s1,s2)=1时,条件成立,执行后面的语句,输出they are Equal。