【发布时间】:2017-06-28 18:40:52
【问题描述】:
今天我尝试做一些新的事情,但我没有做对。谁能做到这一点并解释为什么会这样?提前谢谢你
#include<stdio.h>
void function(int a[],int n)/*The definition of function with void type,with parameters
int a[],int n */
{
int i;// declared count,type integer//
for(i=0;i<n;i++)//count goes from 0,to <n,and increment all time while goes//
printf("%d",a[i++]);// printing on the screen integers (a[i],i=i+1)//
printf("\n");// printing the newline //
}
main()
{
int a[]={1,2,3,4,5,6,7}; // declaration of array with 7 elements //
int n=5;// declaration of variable n type integer value of 5 //
function(a,n) // calling the function with parametres a,n//
} // end of sequence //
在我的情况下,我得到了 1,2,3,4 的结果,因为我认为计数从 1 变为小于 n=5 的一个数,但是 IDE显示 135 的结果,我认为我的问题在于计数器...但欢迎所有建议,谢谢
【问题讨论】:
-
你在循环中增加了两次
i。 -
你将 i 增加了两次
-
@Jean-FrançoisFabre 这对我来说太愚蠢了,我错过了,现在我看到了一个无用的问题,谢谢
-
注意:不要在您的 cmets 中陈述显而易见的内容。这样的 cmets 不会使您的代码更具可读性,而只会增加无意义的噪音。写下你的意图!如果您必须注释每一行,那么您的代码就是错误的。
-
而
main()是一个无效的签名,甚至不是标准的。不允许使用隐式int!