.................
int abc;
char test[20] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
abc = *(int*)test;
..................
Above is a part of c program
Can anybody predict the contents of abc
.................
int abc;
char test[20] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
abc = *(int*)test;
..................
Above is a part of c program
Can anybody predict the contents of abc
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Whatever the 4-bytes of "aaaa" points to; effectively the output of [97979797] in low-byte, high-byte order which is in this case 1633771873. Not that it matters b/c that code has an error in it, trying to shove 29 bytes into a 20-byte sequence so the OP should have wrote:
Trick question. As-written the code will never compile (unless your compiler is an idiot) so what it will output is undetermined.Code:const char * foo = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
Last edited by MK27; 05-18-2010 at 09:31 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
I don't think VS will complain (at least not 2005). I've seen some code that compiles (and works) using syntax like this. It is code that copies an IP address between differing structures, specifically a byte array of length 4 and an in_addr struct.
*(int *)&a->ip = *(int *)&s->sin_addr;