#gesp4h24. 2024GESP四级 函数

2024GESP四级 函数

2024GESP四级 函数

2403真题

1.(2403-1)若函数声明为 int f(int &x){ x+=3; return x; } ,则对声明的变量 int a=3 ,下面哪个调用能够改变 a 的值( )。? {{ select(1) }}

  • f(&a);
  • f(*a) ;
  • f(a) ;
  • f(a-3) ;

2.(2403-3)下面C++代码执行后输出是( )。?

int foo(float *f)
{
	return int(*f*2);
}
int main()
{
    float fnum[10]={1.1};
    fnum[1]=foo(fnum);
    cout << fnum[0]+fnum[1] << endl;
    cout << endl;
    return 0;
}

{{ select(2) }}

  • 1
  • 1.1
  • 3
  • 3.1

2406真题

3.(2406-1)下列代码中,输出结果是()?

#include<iostream>
using namespace std;
int func(int x,int y)
{
	int a=x,b=y;
	int t;
	t=a;
	a=b;
	b=t;
	cout<<a<<" "<<b<<" ";
}
int main()
{
	int c,d;
	c=12;
	d=24;
	func(12,24);
	cout<<c<<" "<<d<<endl;
	return 0;
}

{{ select(3) }}

  • 12 24 24 12
  • 24 12 12 24
  • 12 12 24 24
  • 24 24 12 12

4.(2406-2)下面函数不能正常执行的是()?{{ select(4) }}

  • #include<iostream>
    using namespace std;
    int func()
    {
    	//... 
    }
    int main()
    {
    	//... 
    }
    
  • #include<iostream>
    using namespace std;
    int main()
    {
    	func();
    }
    int func()
    {
    	//... 
    }
    
  • #include<iostream>
    using namespace std;
    int func()
    {
    	//... 
    }
    int main()
    {
    	func();
    }
    
  • #include<iostream>
    using namespace std;
    int func();
    int main()
    {
    	func();
    }
    int func()
    {
    	//... 
    }
    

2409真题

5.(2409-1)在 C++ 中,( )正确定义了一个返回整数值并接受两个整数参数的函数?{{ select(5) }}

  • int add(int a, int b) { return a + b; }
  • void add(int a, int b) { return a + b; }
  • int add(a, b) { return a + b; }
  • void add(int a, int b) { return a - b; }

6.(2409-2)在C++中,形参与实参的关系描述正确的是( )?{{ select(6) }}

  • 形参在函数调用时指定,实参在函数定义时传递
  • 形参在函数定义时指定,实参在函数调用时传递
  • 形参和实参可以互换
  • 形参和实参必须是完全相同的类型,不能有任何差异。

7.(2409-3)运行以下代码,屏幕上将输出( )?

#include <iostream>
using namespace std;

int var = 100;

void function() {
    int var = 200;
    
    cout << var << " ";
    cout << ::var << " ";
}
int main() {
    cout << var << " ";
    
    function();
    
    var += 100;
    cout << var << " ";
    return 0;
}

{{ select(7) }}

  • 100 200 100 200
  • 100 200 100 300
  • 100 200 200 200
  • 100 200 200 300

2412真题

8.(2412-1)下面的语句中,( )正确定义了一个计算浮点数 的平方(x2=x×x)(x^2=x×x )的函数,并成功调用该函数?

{{ select(8) }}

  • float square(float x) {
    	return x * x;
    }
    float area = square(2);
    
  • square(float x) {
    	return x * x;
    }
    float area = square(2);
    
  • void square(float x) {
    	return x * x;
    }
    area = square(2.0);
    
  • void square(float x) {
        x * x;
        return;
    }
    area = square(2);
    

9.(2412-2)下面代码的描述中,正确的是( )?

void n_chars(char c, int n) {
	while (n-- > 0)
		cout << c;
}
char my_char = 'w';
int times = 5;
n_chars(my_char, times);

{{ select(9) }}

  • 代码执行结束后, times 的值为0
  • n 是形参, times 是实参
  • n 是实参, times 是形参
  • 代码最后一行换成 n_chars(times, my_char); 也可以

10.(2412-3)给定以下代码,

void func(int& x) {
	x = x * 2;
}
int a = 5;
func(a);

执行上述代码后,变量 a 的值为( )。

{{ select(10) }}

  • 5
  • 10
  • 15
  • 20

11.(2412-12)给定如下代码,其时间复杂度为( )。

int cellRecur(int n) {
    if (n == 1)
    	return 1;
    return cellRecur(n - 1) + cellRecur(n - 1) + 1;
}

执行上述代码后,变量 a 的值为( )。

{{ select(11) }}

  • O(n2)O(n^2)
  • O(2n)O(2^n)
  • O(1)O(1)
  • O(n)O(n)