小编gra*_*ndx的帖子

"声明会影响参数"是什么意思?

我试图创建一个函数,返回我将传递给它的整数的两倍.我的代码收到以下错误消息:

'int x'的声明会影响参数int x; "

这是我的代码:

#include <iostream>
int doublenumber();
using namespace std;
int doublenumber(int x)// <-- this is the function which returns double the value .
{
    int x;
    return 2 * x;
    cout << endl;
}
int main()
{
    int a;
    cout << "Enter the number that you want to double it : " << endl;
    cin >> a;
    doublenumber(a);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ integer function

8
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×1

function ×1

integer ×1