When learning C ++, the compiler has done a lot of things with us, so let's look at the advanced data structures at the Assembly level and in the memory, efficient writingCodeVery helpful.
Below is a small function that helps you print the content in the memory. If Microsoft compiler is used, byte guard may exist between memory objects, that is, the compiler inserts a blank bytes between the allocated data objects to facilitate detection and destruction of adjacent objects, so it's a little different from the continuous memory allocation in textbooks. Just pay attention to it.
The following code is used to add a test:
# Include <cstdio>
struct test {
int A;
char B;
};
void showbytes (void * s, int N)
{< br> unsigned char * Start = (unsigned char *) s;
printf ("[offset] address: value/n ");
for (INT I = 0; I {< br> printf ("[%. 4d] %. 8x: %. 2x/N ", I, start + I, * (start + I);
If (I + 1) % 4 = 0)
{< br> printf ("----------------------/N");
}< BR >}// for
}
int main ()
{< br> test * t;
Test A = {12, 'A' };< br> T = &;
showbytes (T, 8);
getchar ();
return 0 0;
}