我不明白为什么在初始化为零之后i
设置为0
正确。array
该程序运行良好,因为我reinitialized
value of k
必须i
。但我不知道为什么i
会变成0
. 为什么memset()
要清除数组或将数组设置为0
?
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
long long int i = 123456789;
long long int j = 987654321;
long long int cnt = 0;
int array[9] ;
int xyz, k, x, rem, se;
xyz = 0;
// printf("I = %llf", i);
for (i; (i < j) && (cnt < 100000); i++)
{
k = i;
x = 0;
for (se = 0; se <= 9; se++)
{
array[se] = 0;
}
/*************************************************/
i = k; // Here i becomes zero. Why?
/************************************************/
//memset(array, 0, 9);
while(k != 0)
{
rem = k % 10;
for(se = 0; se <= 9; se++)
{
if(rem == array[se])
{
xyz = 1;
break;
}
}
if(rem == array[se])
{
xyz = 1;
break;
}
array[x++] = rem;
k = k / 10;
}
if (xyz != 1)
{
cnt++;
// printf("Cnt = %d ", cnt);
// printf("The value i is = %lld\n", i);
// Sleep(10);
}
xyz = 0;
// printf("The value i is = %lld\n", i);
// printf("Cnt = %d \n", cnt);
fflush(stdin);
}
printf("The value i is = %lld \n", i-1);
return 0;
}