What about memory address of objects in C++?
I am reading some C++ text and got the following code:
From that code, in the main() function, the author use sizeof() to get the memory address of a开发者_如何学Cll object and its member functions. the results:
From that results, the author made a diagram as follows:
There's no other explanation from the author. What I do not understand is that where the numbers 992, 928, 880, 776 came from? And what is the boundary and why it occupies 8 bytes? Thanks a lot.
The hex addresses 12FF40, 12FF00, 12FED0, 12FE68 are equivalent to the decimal numbers: 1244992, 1244928, 1244880, and 1244776. The least significant digits of these decimal numbers is where the addresses in the diagram come from.
Not sure, but the boundary probably represents padding that causes the object layout to fit onto word boundaries.
精彩评论