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 47043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:03:38+00:00 2026-05-10T16:03:38+00:00

Why does the sizeof operator return a size larger for a structure than the

  • 0

Why does the sizeof operator return a size larger for a structure than the total sizes of the structure’s members?

  • 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. 2026-05-10T16:03:39+00:00Added an answer on May 10, 2026 at 4:03 pm

    This is because of padding added to satisfy alignment constraints. Data structure alignment impacts both performance and correctness of programs:

    • Mis-aligned access might be a hard error (often SIGBUS).
    • Mis-aligned access might be a soft error.
      • Either corrected in hardware, for a modest performance-degradation.
      • Or corrected by emulation in software, for a severe performance-degradation.
      • In addition, atomicity and other concurrency-guarantees might be broken, leading to subtle errors.

    Here’s an example using typical settings for an x86 processor (all used 32 and 64 bit modes):

    struct X {     short s; /* 2 bytes */              /* 2 padding bytes */     int   i; /* 4 bytes */     char  c; /* 1 byte */              /* 3 padding bytes */ };  struct Y {     int   i; /* 4 bytes */     char  c; /* 1 byte */              /* 1 padding byte */     short s; /* 2 bytes */ };  struct Z {     int   i; /* 4 bytes */     short s; /* 2 bytes */     char  c; /* 1 byte */              /* 1 padding byte */ };  const int sizeX = sizeof(struct X); /* = 12 */ const int sizeY = sizeof(struct Y); /* = 8 */ const int sizeZ = sizeof(struct Z); /* = 8 */ 

    One can minimize the size of structures by sorting members by alignment (sorting by size suffices for that in basic types) (like structure Z in the example above).

    IMPORTANT NOTE: Both the C and C++ standards state that structure alignment is implementation-defined. Therefore each compiler may choose to align data differently, resulting in different and incompatible data layouts. For this reason, when dealing with libraries that will be used by different compilers, it is important to understand how the compilers align data. Some compilers have command-line settings and/or special #pragma statements to change the structure alignment settings.

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

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're trying to access a static const on the Event… May 11, 2026 at 5:51 pm
  • Editorial Team
    Editorial Team added an answer You would use forloop.last. For example: <ul> {% for item… May 11, 2026 at 5:51 pm
  • Editorial Team
    Editorial Team added an answer Here is at least part of the problem for the… May 11, 2026 at 5:51 pm

Related Questions

This question was inspired by a similar question: How does delete[] know the size
I am working on a group senior project for my university and I have
I've been comparing a STL implementation of a popular XmlRpc library with an implementation
Why does the following code print ‘read(): Resource temporarily unavailable’ 80% of the time?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.