有以下程序: #include <iostream> #include <strinq> using namespace std; int main() { char a[] = {’a’/’b’/’c’/’

admin2010-03-29  16

问题 有以下程序:    #include  <iostream>    #include  <strinq>    using namespace std;    int main()    {       char  a[] = {’a’/’b’/’c’/’d’,’e’,’f’,’g’,’h’,’\0’};       int  i  j;       i=sizeof(A) ;       j=strlen(A) ;       cout<<i<<","<<j<<end1;       return  0;    }    程序运行后的结果是(    )。

选项 A、9,9
B、8,9
C、1,8
D、9,8

答案8

解析 本题考查sizeof运算符和字符串函数strlen()的区别。
   ①sizeof运算符返回其后表达式或类型标识符所表示的数在内存中所占的字节数。
   ②函数strlen()的功能是返回string的长度,但不包括结束字符’\0’。
   字符数组a在内存中所占的字节数为9。而字符数组a中不包括结束字符’\0’的字符数为8。
转载请注明原文地址:https://jikaoti.com/ti/3iW0FFFM
0

最新回复(0)