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

  • Home
  • SEARCH
  • 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 9198247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:14:33+00:00 2026-06-17T22:14:33+00:00

Possible Duplicate: Pointer arithmetics in C++ uses sizeof(type) incremention instead of byte incremention? Tried

  • 0

Possible Duplicate:
Pointer arithmetics in C++ uses sizeof(type) incremention instead of byte incremention?

Tried to find the answer but could not.
I have the following c++ code:

struct A {
    uint16_t a;
    uint16_t b;
    uint16_t c;
}

int main() {
    uint16_t * B = new uint16_t[5000];
    for (int i=0;i<5000;i++)
        B[i] = i;

    uint16_t * D = &B[500]+sizeof(A);
}

Question is: why *D=512 after this? When I debug sizeof(A) = 6 as it should be. Yet I add to memory address of B[500] the size of A it adds 12 instead of 6.
I am working with memory address still there is a multiplication and I cannot figure out why it is so.

Please advise.

Thank you!

  • 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-17T22:14:34+00:00Added an answer on June 17, 2026 at 10:14 pm

    It’s a compiler bug if sizeof(A) is indeed 6.

    &B[500] + 6 == &B[506]
    

    and thus *D ought to be 506 then. And it is when I compile

    #include <iostream>
    #include <cstdint>
    
    struct A {
        uint16_t a;
        uint16_t b;
        uint16_t c;
    };
    
    int main() {
        uint16_t * B = new uint16_t[5000];
        for (int i=0;i<5000;i++)
            B[i] = i;
    
        uint16_t * D = &B[500]+sizeof(A);
        std::cout << (*D) << std::endl;
        return 0;
    }
    

    with g++-4.7.1 or clang++-3.1.

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

Sidebar

Related Questions

Possible Duplicate: How to find the sizeof(a pointer pointing to an array) Sizeof array
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) sample code
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) I have
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) I know
Possible Duplicate: How to find the sizeof( a pointer pointing to an array )
Possible Duplicate: How to find the sizeof(a pointer pointing to an array) I'm learning
Possible Duplicate: Uses for multiple levels of pointer dereferences? I have used functions with
Possible Duplicate: Typedef function pointer? Could you please help me understand the meaning of
Possible Duplicate: Passing char pointer from C# to c++ function I have this type
Possible Duplicate: pointer as second argument instead of returning pointer? I see this a

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.