Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Why doesn't this end

Name: Anonymous 2010-10-31 5:35

#include <stdio.h>

main()
{

    int a;

while(a != 256)
    {putchar(a);
    a++;}
}

But if I add  a = 0;  after int a;, it ends fine?

Something to do with a variable not being initialized properly, and therefore, not being able to be compared or something?

Compiled with Code::Blocks+GCC or mingw or something. The debugger also reports no relevant issues with the initial code.

Name: Anonymous 2010-10-31 7:39

>>13,14
Are you fucking serious?
implicit that variables are initialized to -max
In >>8 it is apparent that variables are not initialised unless you explicitly initialise them.
Meanwhile, printf("%d", a) prints the decimal value of a.
putchar prints the (ASCII) character a.
fputc() writes the character c, cast to an unsigned char, to stream.
putc() is equivalent to fputc() except that it may be implemented as a macro which evaluates stream more than once.
putchar(c); is equivalent to putc(c,stdout).


There are 4294967040 values of int outside of the range of a char. This is why it ``doesn't work''.
IHBMFT

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List