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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:10:59+00:00 2026-06-18T01:10:59+00:00

I am aware of padding, and its rules, why it requires etc. My question

  • 0

I am aware of padding, and its rules, why it requires etc.

My question is given struct,

struct my_struct {
   int a;
   char c;
};

In this case start address of c is word align, but still compiler added 3 bytes (assuming 4 as word size) padding. with no element after c and why we need these 3 bytes?
I checked following,

int g_int1;
struct my_struct st;
int g_int2;

by above what I mean is my rest of variable declarations are not dependent on word align-ness of previous variable size. compiler always try to align next variable irrespective of its global or local auto var.

I cant see any reason with endian-ness since this is char and for one byte it don’t matters. what reason I think is instead of checking last element condition compiler always add padding whenever required.

what can the valid reason?

  • 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-18T01:11:00+00:00Added an answer on June 18, 2026 at 1:11 am

    Because if sizeof(my_struct) was 5 rather than 8, then if you did this:

    my_struct array[2];
    

    then array[0] would be word-aligned, but array[1] would not be. (Recall that array lookup is done by adding multiples of sizeof(array[0]) to the address of the first element.)

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

Sidebar

Related Questions

I aware that this will be a less programming question, but still... How can
This question is for educational purposes only. I am aware of how a native
I am aware about the concepts of data type or structure alignment, packing, padding
Python's len() and padding functions like string.ljust() are not tabstop-aware, i.e. they treat '\t'
I'm aware of a lot of css nice solutions etc... short being told, I
Be aware that I might be doing this totally wrong, so I apologize in
This is my first question on this site, and I only have a basic
Are aware of any solution that let me deactivate my facebook account through an
BE AWARE! Creating spyware, computer viruses and similar nasties can be illegal where you
Data-aware controls can be linked to datasets to display data contained in fields in

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.