问题
单项选择题
以下程序中函数f( )的功能是将n个字符串按由大到小的顺序进行排序。 #include<string.h> void f(char p[ ][10],int n) { char t[20]; int i,j; for(i =O;i <n-1 ;i ++ ) for(j =i + 1 ;j < n;j ++ ) if(strcmp(p [i] ,p[j] ) <0) { strcpy(t,p[i]);strcpy(p[i] ,p[j] );strcpy(p[j] ,t); } } main ( ) { char p [ ] [ 10 ] = { "abc","aabdfg","abbd","dcdbe", "cd" }; int i; f(p,5); printf("%d\n",strlen(p[O] ) ); } 程序运行后的输出结果是( )。
A.6
B.4
C.3
D.5
答案
参考答案:C
解析:对字符串比较的方法是依次对两字符串对应位置上的字符两两比较,当出现第一对不相同的字符 时,即由这两个字符(ASCII码值)决定所在串的大小。