【发布时间】:2017-05-11 20:42:42
【问题描述】:
对编程非常陌生,并被要求在程序代码中查找错误作为教程。在尝试修复它时,对于标记为传递单个元素的行,我不断收到“'int'类型的参数与'int'类型的参数不兼容”这一行。没有学过指针,也不是很了解函数是怎么工作的,所以其他地方可能会出错。
#include <iostream>
using namespace std;
void functionA ( int num[] ) ;
void functionB ( int newnumbers[] ) ;
void functionC ( int newnumbers[] ) ;
void main ()
{
int numbers[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } ;
int i;
for ( i=0; i<10; i++ )
functionA ( numbers[i] ) ; // passing individual elements
cout << "\n\n" ;
functionB ( numbers ) ; // passing the whole array
functionC ( numbers ) ; // passing the whole array
cout << "\n\n" ;
}
void functionA ( int num[] )
{
cout << num << " " ;
}
void functionB ( int newnumbers[] )
{
for ( int i=0; i<10; i++ )
newnumbers[i] = newnumbers[i] * 5 ;
}
void functionC ( int newnumbers[] )
{
for ( int i=0; i<10; i++ )
cout << newnumbers[i] << " " ;
}
【问题讨论】:
标签: c++