.................
int abc;
char test[20] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
abc = *(int*)test;
..................
Above is a part of c program
Can anybody predict the contents of abc
Printable View
.................
int abc;
char test[20] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
abc = *(int*)test;
..................
Above is a part of c program
Can anybody predict the contents of abc
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";
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;