开发者

What about memory address of objects in C++?

开发者 https://www.devze.com 2023-03-18 01:54 出处:网络
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

I am reading some C++ text and got the following code:

What about memory address of objects in C++?

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:

What about memory address of objects in C++?

From that results, the author made a diagram as follows:

What about memory address of objects in C++?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消