#3169. [GESP202503 四级 C++] 第 1 题

[GESP202503 四级 C++] 第 1 题

关于下述代码,说法错误的是( )。

int multiply(int x, int y);

int main() {
    int a = 4;
    int b = 5;
    int result = multiply(a, b);
    std::cout << "The result is: " << result << std::endl;
    return 0;
}

int multiply(int x, int y) {
    return x * y;
}

{{ select(1) }}

  • 函数 multiply 的定义应该放到函数 main 之前。
  • 函数声明 int multiply(int x, int y); 中明确指定了函数 multiply() 的返回值为整数类型。
  • main 函数中,函数 multiply 通过 multiply(a, b) 被调用,其中 ab 是定义在 main 函数中的变量,它们作为实参传递给了 multiply 函数的形参 xy
  • 运行上述代码,将输出 The result is: 20