#6151. gesp三级真题分类三:C++ 基础语法

gesp三级真题分类三:C++ 基础语法

C++ 基础语法(共20题)

  1. 定义 char str[10] = "GESP",则 sizeof(str) 的值是( ) {{ select(1) }}
  • 4
  • 5
  • 10
  • 不确定
  1. 下列字符串操作中,会修改原字符串的是( ) {{ select(2) }}
  • s.substr(1,3)
  • s.find('a')
  • s.replace(0,2,"abc")
  • s.length()
  1. 定义 int a[5] = {1,2,3},则 a[3] 的值是( ) {{ select(3) }}
  • 0
  • 3
  • 随机值
  • 编译错误
  1. 执行 string s = "123"; int x = s[0]; 后,x 的值是( ) {{ select(4) }}
  • 1
  • '1'
  • 49
  • 编译错误
  1. 下列哪种类型转换是隐式转换?( ) {{ select(5) }}
  • int a = (int)3.14;
  • double b = 5;
  • char c = 'A' + 1;
  • string s = "hello" + "world";
  1. 下列数组定义中,错误的是( ) {{ select(6) }}
  • int a[] = {1,2,3};
  • int a[3] = {1,2,3};
  • int a[3] = {1,2,3,4};
  • int a[3] = {0};
  1. 以下代码输出结果是( )
    int a = 3, b = 2;
    cout << a / b * 1.0;
    
    {{ select(7) }}
  • 1.5
  • 1
  • 1.0
  • 编译错误
  1. 下列字符串初始化中,正确的是( ) {{ select(8) }}
  • string s = 'hello';
  • string s = "hello";
  • string s = hello;
  • string s = 123;
  1. 对于 int arr[10],下列访问正确的是( ) {{ select(9) }}
  • arr[0]
  • arr[10]
  • arr[-1]
  • arr[10.5]
  1. 下列代码输出结果是( )
    int a[3] = {1,2,3};
    cout << a[1] << endl;
    
    {{ select(10) }}
  • 1
  • 2
  • 3
  • 随机值
  1. 字符串 "GESP" 和字符数组 {'G','E','S','P'} 完全等价。( ) {{ select(11) }}
  • 正确
  • 错误
  1. int a[10] = {0} 将数组中所有元素初始化为 0。( ) {{ select(12) }}
  • 正确
  • 错误
  1. cout << (3/2*1.0) 输出 1.5。( ) {{ select(13) }}
  • 正确
  • 错误
  1. string s = "GESP"; s[4] 访问不会导致运行时错误。( ) {{ select(14) }}
  • 正确
  • 错误
  1. char c = 65; cout << c; 输出 A。( ) {{ select(15) }}
  • 正确
  • 错误
  1. int a[5]; 定义后,所有元素的值默认为 0。( ) {{ select(16) }}
  • 正确
  • 错误
  1. string s = "Hello"; s.length()s.size() 返回值相同。( ) {{ select(17) }}
  • 正确
  • 错误
  1. int a[3] = {1,2}; 中,a[2] 的值是 0。( ) {{ select(18) }}
  • 正确
  • 错误
  1. char str[5] = "GESP"; 中,str[4] 的值是 '\0'。( ) {{ select(19) }}
  • 正确
  • 错误
  1. cout << "GESP" << endl; 会输出 GESP 并换行。( ) {{ select(20) }}
  • 正确
  • 错误