- 论坛徽章:
- 145
|
本帖最后由 jason680 于 2014-09-05 12:55 编辑
回复 14# sxcong
They are different with
sometime you get the zero with uninitialized variable
always you get the zero with initialized variable
and try bellow:
$ cat count.c
#include <stdio.h>
#include <stdlib.h>
int count( void ){
int k, i;
for (i = 0; i < 10; i++){
k = k + 1;
}
return(k);
}
int main(void){
int c;
for(c=0; c <=10; c++){
printf("%d, ", count());
}
printf("\n");
return(0);
}
$ gcc -o count count.c
$ ./count
7996398, 7996408, 7996418, 7996428, 7996438, 7996448, 7996458, 7996468, 7996478, 7996488, 7996498,
$ ./count
2843630, 2843640, 2843650, 2843660, 2843670, 2843680, 2843690, 2843700, 2843710, 2843720, 2843730,
-------------------------------------------------
Note: initialized variable
int k=0, i;
$ ./count
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
$ ./count
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
|
|