gpt4 book ai didi

c - 以下代码的输出是什么?

转载 作者:行者123 更新时间:2023-11-30 21:15:29 25 4
gpt4 key购买 nike

main()
{

int a[ ] = { 2, 4, 6, 8, 10 } ;
int i ;
change (a, 5 ) ;
for ( i = 0 ; i <= 4 ; i++ )
{
printf( "\n%d", a[i] ) ;
}
}
change ( int *b, int n )
{
int i ;
for ( i = 0 ; i < n ; i++ )
*( b + i ) = *( b + i ) + 5 ;
}

我无法计算上述代码的输出。在 http://www.compileonline.com/compile_c_online.php 上编译程序时显示的问题位于change()函数的定义处。发现错误:错误:更改之前的预期表达式(int *b,int n)。我不明白这是什么意思。需要什么样的表达方式。如果 b 是指针(它具有 a 的地址),那么我们如何通过添加 i 来更改其地址值。

最佳答案

您不能在 C 中嵌套函数。请将 change 函数的定义移至 main 函数之外。

现代 C 还要求您在函数声明中指定返回类型,例如例如,int main(void)void change (int *b, int n)

编辑:问题已被编辑,现在 change 函数不再嵌套。现在OP需要在main函数之前声明change

关于c - 以下代码的输出是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26084138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com