#C1050. 字符串选择题测试

字符串选择题测试

  1.  \ 有如下定义,则 str[5] 的值是( )
char str[] = "hello";

{{ select(1) }}

  • 'o'
  • '\0'
  • 'h'
  • 不确定

  1.  \ 关于下面两个数组,说法正确的是( )
char a[] = "abc";
char b[] = {'a', 'b', 'c'};

{{ select(2) }}

  • 两者末尾都自动有 '\0'
  • a 末尾有 '\0',b 末尾没有自动补 '\0'
  • b 末尾会自动补 '\0'
  • 两者末尾都没有 '\0'

  1.  \ 执行下面代码,输出是( )
string s = "hello";
s[0] = 'H';
s += "!";
cout << s;

{{ select(3) }}

  • hello!
  • Hello
  • Hello!
  • 编译错误

  1.  \ 执行下面代码,输入 hello world 后回车,输出是( )
string s;
cin >> s;
cout << s;

{{ select(4) }}

  • hello world
  • hello
  • world
  • 空

  1.  \ 执行下面代码,输入 hello world 后回车,输出是( )
string s;
getline(cin, s);
cout << s;

{{ select(5) }}

  • hello world
  • hello
  • world
  • 空

  1.  \ 执行下面代码,输入 Tom 后回车,输出是( )
char name[20];
cin >> name;
cout << name;

{{ select(6) }}

  • Tom
  • T
  • om
  • 空

  1.  \ 执行下面代码,输出是( )
string s1 = "abc", s2 = "abc";
cout << (s1 == s2);

{{ select(7) }}

  • 0
  • 1
  • abc
  • 编译错误

  1.  \ 下列哪个语句能把 "world" 接到 string 变量 s 原有内容之后?( )

{{ select(8) }}

  • s = "world";
  • s += "world";
  • s[0] = "world";
  • s + "world";

  1.  \ 执行下面代码,输出是( )
char c[] = "abc\0def";
cout << c;

{{ select(9) }}

  • abc
  • abcdef
  • abc\0def
  • 编译错误

  1.  \ 执行下面代码,输出是( )
string s = "abc";
s = s + "def";
cout << s;

{{ select(10) }}

  • abc
  • def
  • abcdef
  • abc def