Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:12:52+00:00 2026-06-14T18:12:52+00:00

I recently tried debugging a small program by printing the values of several pointers

  • 0

I recently tried debugging a small program by printing the values of several pointers to the console. The first was the memory address of a struct, and the others were the memory addresses of its fields. A stripped-down version of the code is as follows:

#include <iostream>

struct testingPointers
{
    int i;
    float f;
    double d;
} test;

int main()
{
   std::cout << &test << '\n' << &(test.i) << '\n' << 
            &(test.f) << '\n' << &(test.d);
}

And the output is:

0x681110
0x681110
0x681114
0x681118

(obviously the exact values are different for different runs but they always have the same positions relative to each other).

I am confused because the value of first pointer–the memory location of test–is the same as that of the second one (the first field of test). Does this mean that objects have no real unique memory address, and that a pointer to a struct or class simply points to its first field? If so, how do statements like

a.b
a->b
a.b()

make sense if a is actually just its first field, and therefore does not have any fields or methods?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:12:53+00:00Added an answer on June 14, 2026 at 6:12 pm

    A class or struct just describes a collection of fields that should be kept together in memory, and have some semantic relationship between them and some operations that operate over them. There is, in the simple case, nothing much more to the content of a class type object in memory than the members it is made up of (and some padding). When you have a testingPointers object in memory, it is really just an int, a float and a double. The concept of the class was only used to generate the correct executable code – it does not exist at run time (at least not for this purpose).

    The important part from the standard regarding whether objects can share memory addresses is §1.8/6:

    Unless an object is a bit-field or a base class subobject of zero size, the address of that object is the address of the first byte it occupies. Two objects that are not bit-fields may have the same address if one is a subobject of the other, or if at least one is a base class subobject of zero size and they are of different types; otherwise, they shall have distinct addresses.

    We can infer from this that because member test.i is a subobject of test, they may well have the same address.

    Once you look inside all of the objects of your program as deep as you can go, what you really have is a big collection of scalar values and adjacent bit-fields. These are known as memory locations in the standard. These are the things that really take up space. The rest of your objects are all in some way composed of these.

    A memory location is either an object of scalar type or a maximal sequence of adjacent bit-fields all having non-zero width. [ Note: Various features of the language, such as references and virtual functions, might involve additional memory locations that are not accessible to programs but are managed by the implementation. — end note ]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I tried compiling program something like this with GCC: int f(int i){ if(i<0){
I recently tried to combine SEAM and GWT in a project - but failed
I recently tried to figure out how to use freeglut with NetBeans 7. I
I recently tried using the Cloud9 online IDE . It starts by creating a
I recently tried to pull some results and was struggling to work out the
I've recently tried to optimize my site for speed and brandwith. Amongst many other
I'm recently tried to make a custom tabcontrol that able to move the tab
Recently I tried to explain some poorly designed code to my project manager. All
Recently I tried to install a webpart through wspbuilder utility to the Sharepoint Site.
Here's the thing. Recently I've tried to add FB like button to some website

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.