#G072. GESP level3 程序阅读题

GESP level3 程序阅读题

GESP level3 - 程序阅读题

  1. 下列代码中,输出结果是( )
    
    #include
    using namespace std;
    int main(){
    double a=0.9;
    double b=1.0;
    if(((b-a)==0.1)) {
    cout<<"Equal"<<endl;
    }
    else{
    cout<<"Not equal"<<endl;
    }
    }
    
    {{ select(1) }}
  • Equal
  • Not equal
  • 程序不能正确执行
  • 没有输出
  1. 关于计算机中的编码,下列说法中正确的是()
    
    A. 机器数的形式值和真值是一致的
    B. 原码就是符号位加上真值
    C. 机器数是带符号的
    D. [-1]=[1000 0001]原=[1111 1111]反
    
    {{ select(2) }}
  • A
  • B
  • C
  • D
  1. 下列代码实现的是( )
    
    void Swap(int &a, int &b) {
    if (a != b) {
    a ^= b;
    b ^= a;
    a ^= b;
    }
    }
    
    {{ select(3) }}
  • a和b的异或
  • a和b的同或
  • a和b的值交换
  • a和b的高低位互换
  1. a&~1运算实现的是( )
    
    A. 使a的最低位为1
    B. 使a的最高位为1
    C. 使a的最低位为0
    D. 使a的最高位为0
    
    {{ select(4) }}
  • A
  • B
  • C
  • D
  1. 下列程序中,result和result2输出分别是( )
    
    long a = 123;
    int b = 1;
    long result = a & b;
    cout<<result<<endl;
    long a2 = -123;
    unsigned int b2 = -1;
    long result2 = a2 & b2;
    cout<<result2<<endl;
    
    {{ select(5) }}
  • 123 -1
  • 123 -123
  • 1 -1
  • 1 -123
  1. 下面的程序中,会输出( )
    
    int a[10]={1,2,3,4,5,6,7,8,9,10};
    cout<<a[10]<<endl;
    
    {{ select(6) }}
  • 1
  • 0
  • 10
  • 不确定的值
  1. 下列程序输出的是()
    
    string str = "Hello,CHAD";
    cout << str.find("A") << '\n';
    
    {{ select(7) }}
  • 9
  • 8
  • 7
  • 6
  1. 下面C++代码执行后的输出是( )
    
    int temp=0;
    for(int i=1;i<7;i++)
    for(int j=1;j<5;j++)
    if(i/j==2)
    temp++;
    cout<<temp<<endl;
    
    {{ select(8) }}
  • 10
  • 8
  • 4
  • 3
  1. 执行下面C++代码后输出的是( )
    
    string str("chen");
    int x=str.length();
    cout<<x<<endl;
    
    {{ select(9) }}
  • 4
  • 3
  • 2
  • 5
  1. 下面C++代码执行后的输出是( )
    
    char ch[10]={'1'};
    cout<<ch[2]<<endl;
    
    {{ select(10) }}
  • 0
  • 1
  • 输出空格
  • 什么也不输出
  1. 下面C++代码用于统计每种字符出现的次数,当输出为3时,横线上不能填入的代码是( )
    
    string str="GESP is a good programming test";
    int x=0;
    for(int i=0;i<str.length();i++)
    if(______)
    x++;
    cout<<x<<endl;
    
    {{ select(11) }}
  • str[i]=='o'
  • str[i]=='a'+14
  • str[i]==115
  • str[i]==111
  1. 执行下面C++代码后输出的是( )
    
    string str="chen";
    int x=str.length();
    for(int i=0;i<=x;i++)
    temp++;
    cout<<temp<<endl;
    
    {{ select(12) }}
  • 4
  • 2
  • 5
  • 3
  1. 如果数组定义为long long array[] = {3, 5, 7, 2}; ,则数组array 占用的字节数为( ) {{ select(13) }}
  • 32
  • 16
  • 8
  • 4
  1. 一个数组定义为double array[3]; ,则可合理访问这个数组的元素的下标最大为( ) {{ select(14) }}
  • 2
  • 3
  • 23
  • 24
  1. 下列关于C++语言中数组的叙述,不正确的是( )
    
    A. 可以定义0 个元素的数组
    B. 不能定义-1 个元素的数组
    C. 数组下标越界访问会产生编译错误
    D. 程序运行时发生数组下标的越界访问,程序依然可能正常结束
    
    {{ select(15) }}
  • A
  • B
  • C
  • D
  1. 在下列代码的横线处填写( ),可以使得输出是“20 10”
    
    #include 
    using namespace std;
    int main(){
    int a=10,b=20;
    a=(a<<8)|b;
    ____//在此处填入代码
    cout<<a<<" "<<b<<endl;
    return0;
    }
    
    {{ select(16) }}
  • a = a >> 8; b = a & 0xff
  • b = a >> 8; a = a & 0xff;
  • a = b; b = a & 0xff;
  • b = a; a = b;
  1. 执行下面C++代码后输出的第一个数是( )
    
    int main(){
    int a[20],i;
    for(i = 0; i < 20; i++)
    a[i] = i+1;
    for( ; i > 0; i--)
    cout << a[i-1] << " ";
    }
    
    {{ select(17) }}
  • 20
  • 19
  • 1
  • 不确定
  1. 已知字符'0' 的ASCII编码的十进制表示为48,则执行下面C++代码后,输出是( )
    
    int main() {
    string s="316";
    int n=s.length();
    int x=0;
    for(int i = 0; i < n; i++)
    x += s[i];
    cout << x << endl;
    }
    
    {{ select(18) }}
  • 10
  • 58
  • 154
  • 316
  1. 下面C++代码执行后数组中大于0的数的特征是( )
    
    int main() {
    int a[20],i;
    for(i = 0; i < 20; i++)
    a[i] = i+1;
    for(int i = 0; i < 20; i++)
    if((a[i]%2)&&(a[i]%3))
    a[i] = 0;
    for(i = 0; i < 20; i++)
    if(a[i]) cout << a[i] << " ";
    }
    
    {{ select(19) }}
  • 2的倍数
  • 3的倍数
  • 能被2或3整除的数
  • 能被2和3同时整除的数
  1. 在下列代码的横线处填写( ),可以使得输出是“7”
    
    #include 
    using namespace std;
    int main() {
    int array[5] = {3,7,5,2,4};
    int max = 0;
    for(int i=0; i<5; i++)
    if(_____)
    max = array[i];
    cout << max << endl;
    }
    
    {{ select(20) }}
  • max > array[i]
  • max < array[i]
  • max = array[i]
  • 以上均不对
  1. 下列程序输出的是( )
    
    string ch="hello";
    if(ch[5]NULL)
    {
    cout<<"right"<<endl;
    }
    else if (ch[5]'\0')
    {
    cout<<"wrong"<<endl;
    }
    else
    {
    cout<<"hello"<<endl;
    }
    
    {{ select(21) }}
  • right
  • wrong
  • hello
  • 不能正确执行
  1. 下列程序最后输出的是()
    
    int a=65;
    cout<<tolower(a)<<endl;
    
    {{ select(22) }}
  • 65
  • A
  • a
  • 97
  1. 在下列代码的横线处填写( ),可以使得输出不是“31”
    
    #include 
    using namespace std;
    int main(){
    int array[5] = {1,2,4,8,16};
    int res=0;
    for(int i=0;i<5;i++)
    ______;
    cout<<res<<endl;
    }
    
    {{ select(23) }}
  • res = res + array[i]
  • res = res & array[i]
  • res = res | array[i]
  • res = res ^ array[i]