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

Pi

Name: Anonymous 2010-06-03 14:55

int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c;)f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[b]*a,
f[b]=d%--g,d/=g--,--b;d*=b);}

Name: Anonymous 2010-06-05 10:22

int a = 10000, b, c=2800, d, e, f[2801], g;
main()
{
   for(; b - c; )
   {
      f[b++] = a/5;
   }
   for(; d = 0, g = c*2 ; c -= 14, printf("%.4d",e+d/a),e=d%a)
   {
      for(b = c; d += f[b]*a, f[b] = d%--g, d /= g--, --b; d *= b);
   }
}


>>6
For starters, four of your variables remain uninitialized (only SOME systems accept that) and all of your loops are broken in some way.  For your first loop, you are probably hoping that b is auto-initialized to 0 and that the loop will terminate when b - c is equal to 2800 - 2800; in practice, b will be initialized to whatever junk data is stored at the memory location allocated for b and should not be trusted.  It could be a negative number and that would try to access array data at negative indices.  The same goes for all uninitialized variables.

For your second loop, it lacks a proper conditional statement and statements that should have been placed in the initialization block are in the conditional block.

The third loop also lacks a test condition statement.  I'm going to make a guess but based on what it looks like one of the conditional statements should be whether b is less than zero.  This is just a shot in the dark:

for(b = c; b >= 0 && ...; d += f[b]*a, f[b] = d%--g, d /= g--, --b, d *= b);

Name: Anonymous 2010-06-05 16:32

>>7
None of his loops lack proper conditional statements. l2C.
It's true that he's depending on auto-initialisation to 0, which isn't guaranteed at all. However,

b will be initialized to whatever junk data is stored at the memory location allocated
Memory is cleared by the OS before it is allocated to applications in every OS that does memory protection (and most that don't). I know it's a popular misconception that uninitialised variables will contain whatever happened to be there from the last time an application used that bit of memory, but that's total toss.

Anyway, the main problems are lack of initialisation and a malformed main declaration. Sensible compilers and platforms would reject the code altogether, but it will probably do what he expects it to on most.

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