问题
单项选择题
有以下程序:
#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;
B.8,9
C.1,8
D.9,8
答案
参考答案:D
解析: 本题考查sizeof运算符和字符串函数strlen()的区别。
①sizeof运算符返回其后表达式或类型标识符所表示的数在内存中所占的字节数。
②函数strlen()的功能是返回string的长度,但不包括结束字符'\0'。
字符数组a在内存中所占的字节数为9。而字符数组a中不包括结束字符'\0'的字符数为8。