I was writing some low level c code on fedora 14, but going nuts over this piece of code. The first array is not initialized to '0', the second is. Gone through gdb several times, but it's like magic. What is happening?
const int maxsize=100000;
char num[7];
char tnum[6];
int pos=0;
while(pos<(maxsize+1)) {
int c=0;
int j=0;
int myindex;
int tindex;
for(myindex=0;myindex<7;myindex++) num[myindex]='0';
for(tindex=0;tindex<6;tindex++) tnum[tindex]='0';
//....
}
I printed the array values inside gdb, both as p num , p tnum and as p num[0] and p tnum[0].
I also tried to initialize as plain 0, same thing also happens.
Here is the debugger output
Temporary breakpoint 1, main () at inversionscount.c:3
3 int main() {
Missing separate debuginfos, use: debuginfo-install glibc-2.13-1.i686
(gdb) s
5 const int maxsize=100000;
(gdb) s
6 int startarray[maxsize];
(gdb) s
14 int pos=0;
(gdb) s
15 while(pos<(maxsize+1)) {
(gdb) s
19 int c=0;
(gdb) s
20 int j=0;
(gdb) s
24 for(myindex=0;myindex<7;myindex++) num[myindex]='0';
(gdb) s
25 for(tindex=0;tindex<6;tindex++) tnum[tindex]='0';
(gdb) s
27 while( c=getchar()!="\n") {
(gdb) p num
$1 = "\370\377\277\270\367\377"
(gdb) p tnum
$2 = "000000"
(gdb)
maxsize?whileloop here?bzerois not a Standard C function and is deprecated in POSIX