#2475. ws控制语句和数组

ws控制语句和数组

  1. 以下数组声明正确的是: {{ select(1) }}
  • int array[];
  • int array[5] = {1,2,3,4,5,6};
  • int array[3] = {1,2,3};
  • int array[0];
  1. 对于数组 int arr[5],有效下标范围是: {{ select(2) }}
  • 0-4
  • 1-5
  • 0-5
  • 1-4
  1. 以下代码的输出结果是:
int arr[4] = {2,4,6,8};
cout << arr[2];

{{ select(3) }}

  • 2
  • 4
  • 6
  • 8
  1. 以下代码的输出结果是:
int nums[5] = {1};
for(int i=0; i<5; i++) {
    cout << nums[i];
}

{{ select(4) }}

  • 1
  • 10000
  • 11111
  • 00000
  1. 数组元素在内存中的存储方式是: {{ select(5) }}
  • 随机存储
  • 链式存储
  • 连续存储
  • 树形存储
  1. 以下代码的输出结果是:
int arr[] = {1,3,5,7,9};
int sum = 0;
for(int i=0; i<5; i+=2) {
    sum += arr[i];
}
cout << sum;

{{ select(6) }}

  • 15
  • 25
  • 9
  • 16
  1. 以下代码的输出结果是:
int a[3] = {1,2,3};
int b[3];
for(int i=0; i<3; i++) {
    b[i] = a[2-i];
}
cout << b[1];

{{ select(7) }}

  • 1
  • 2
  • 3
  • 0
  1. 以下代码的输出结果是:
int arr[5] = {5,4,3,2,1};
int result = 0;
for(int i=1; i<4; i++) {
    if(arr[i] > arr[i-1]) {
        result += arr[i];
    }
}
cout << result;

{{ select(8) }}

  • 0
  • 4
  • 7
  • 9
  1. 以下代码的输出结果是:
int numbers[6] = {2,1,4,3,6,5};
int count = 0;
for(int i=0; i<6; i++) {
    if(numbers[i] % 2 == 0 && i % 2 == 0) {
        count++;
    }
}
cout << count;

{{ select(9) }}

  • 1
  • 2
  • 3
  • 4
  1. 以下代码的输出结果是:
int data[4] = {3,7,2,9};
int max_val = data[0];
for(int i=1; i<4; i++) {
    if(data[i] > max_val) {
        max_val = data[i];
    }
}
cout << max_val;

{{ select(10) }}

  • 3
  • 7
  • 2
  • 9
  1. 以下代码的输出结果是:
int arr[5];
for(int i=0; i<5; i++) {
    arr[i] = i * i;
}
cout << arr[3];

{{ select(11) }}

  • 3
  • 6
  • 9
  • 12
  1. 以下代码的输出结果是:
int seq[5] = {1};
for(int i=1; i<5; i++) {
    seq[i] = seq[i-1] * 2 + 1;
}
cout << seq[3];

{{ select(12) }}

  • 3
  • 7
  • 15
  • 31
  1. 关于C++变量,以下说法正确的是: {{ select(13) }}
  • 变量名可以以数字开头
  • 变量名可以包含空格
  • 变量在使用前必须先声明
  • 变量名可以是C++关键字
  1. 以下for循环会执行多少次?
for(int i=1; i<=10; i+=2) {
    // 循环体
}

{{ select(14) }}

  • 5次
  • 10次
  • 6次
  • 4次
  1. 以下while循环会执行多少次?
int n = 8;
while(n > 1) {
    n /= 2;
}

{{ select(15) }}

  • 2次
  • 3次
  • 4次
  • 无限循环
  1. 以下代码的输出结果是:
int x = 15;
if(x > 10 && x < 20) {
    cout << "A";
} else if(x > 5) {
    cout << "B";
} else {
    cout << "C";
}

{{ select(16) }}

  • A
  • B
  • C
  • AB
  1. 以下哪个是合法的变量名? {{ select(17) }}
  • 2nd_value
  • my-var
  • _temp
  • float
  1. 以下代码的输出结果是:
int a = 5, b = 3;
if(a++ > 5 || b-- < 3) {
    cout << a << b;
} else {
    cout << b << a;
}

{{ select(18) }}

  • 53
  • 63
  • 34
  • 26
  1. 以下哪个数据类型占用内存最小? {{ select(19) }}
  • int
  • double
  • char
  • float
  1. 以下代码的输出结果是:
int i = 0;
do {
    cout << i;
    i++;
} while(i < 3);

{{ select(20) }}

  • 012
  • 0123
  • 12
  • 123