c++ - 输出不是预期的

标签 c++ compiler-errors codeblocks

#include<iostream>  
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<stdio.h>


using namespace std;



int swapper(int n[],int s
)
{
for(int i=0;i<s;i++)
{
    int temp=n[i];
    n[i]=n[i+1];
    n[i+1]=temp;
}
cout<<"\n Array Swapped !!!";
for (int i=0;1<s;i++)
{

    cout<<n[i]<<"\t";
}
return 0;
  }


int main()

 { 
 int n[20]; int s;

cout<<"\n enter array size:";

cin>>s;
cout<<"enter no in array according to size given";

for(int j=0;j<s;j++)

    {

        cin>>n[j];

    }

 swapper(n,s);

 return 0;

 getch();

 }

该程序的输出不交换数组元素,
相反,它开始大量产生数字
整个代码都写在这里
所有其他建议的更改已进行

该函数应该采用一个整数数组及其大小作为参数,并显示一个交换了其相邻元素的数组。

最佳答案

通话

swapper(n[],s);

是不正确的。假设swapper的第一个参数是int*,则必须为:
swapper(n,s);

关于c++ - 输出不是预期的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34972514/

相关文章:

c++ - 对std::vector使用嵌套的[]操作

c++ - 基指针中的派生对象如何调用基函数?

c# - 使用 LINQ 返回产品价格,在函数中使用什么返回类型?

gcc - 使用 -L 专门查找库时获取 'error while loading shared libraries'

c - 构建C程序时如何解决CodeBlocks中的这个 'Multiple Definitions of'错误?

c++ - C/C++ 程序将输出(int)返回给其他程序

c++ - 为什么预先声明 std::basic_string<T> 会破坏 boost::regex?

检查斐波那契素数的项数

c++ - SDL 应用程序无法在其他计算机上运行

c++ - 在 C++ 类中实现 TPCircularBuffer