low-level question



I couldn't get this on a midterm. Darn!

Anyone want to help?

1. Why does the following program output a 0?
2. Explain in detail.
3. How could you prevent this outcome without changing the code?


#include <stdio.h>
#include <string.h>

int
main( int argc, char *argv[] )
{
int ii = 1;
char buf[ 4 ];

strcpy( buf, "AAAA" );

printf( "%d\n", ii );

return 0;
}

.



Relevant Pages

  • Re: low-level question
    ... Darn! ... Why does the following program output a 0? ... > int ii = 1; ... This is still undefined behavior according to the ...
    (comp.lang.c)
  • Re: low-level question
    ... Darn! ... Why does the following program output a 0? ... If ii is allocated just after the end of buf, and if the platform uses ... a little-endian representation for int, ...
    (comp.lang.c)
  • Re: Serious conformance bug in
    ... Compiled with gcc in C99 mode, program output is: ... Warning foo.c: 8 printf argument mismatch for format u. Expected long long got unsigned int ...
    (comp.lang.c)
  • Re: Reading Simple Flatfiles with a COBOL Mindset
    ... PROGRAM OUTPUT: ... Input file: pres.txt ... char *get_string (char*, const char*, int); ...
    (comp.lang.c)
  • Re: Comparing Dates in JSP
    ... Darn maybe I should have just copied and pasted ... Date travel = sdf.parse; ... //this is where I expect to get an int that represents how many days ... //and this is where I get errors when compiling, ...
    (comp.lang.java.help)