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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:15:35+00:00 2026-06-17T06:15:35+00:00

According to byte padding, in 32 bit OS, the CPU can address memory in

  • 0

According to byte padding, in 32 bit OS, the CPU can address memory in multiple of 4 as given here when the computer’s word size is 4 bytes (a byte meaning 8 bits), the data to be read should be at a memory offset which is some multiple of 4. When this is not the case, e.g. the data starts at the 14th byte instead of the 16th byte, then the computer has to read two 4-byte chunks and do some calculation before the requested data has been read, or it may generate an alignment fault. Even though the previous data structure ends at the 14th byte, the next data structure should start at the 16th byte. Two padding bytes are inserted between the two data structures to align the next data structure to the 16th byte.

#include<stdio.h>
struct test {
        char a;
        char b;
        int c;
        int d;
};
void main() {
        int a,b;
        char c,d;
        printf("Address of a & b = %u & %u respectively\n",&a,&b);
        printf("Address of c & d = %u & %u respectively\n",&c,&d);      
        struct test t1;
        printf("The size of structure:::%d\n",sizeof(t1));
}

Output is:

Address of a & b = 3216087804 & 3216087808 respectively
Address of c & d = 3216087802 & 3216087803 respectively
The size of structure:::12

While when I declared structure in this way:

struct test {
        char a;
        int b;
        int c;
        char d;
};

Output in this case:

The size of structure:::16

Why alignment fault will not occur when we try to access secord char variable at odd location in memory or variable which is not exist at address which is in multiple of 4?

  • 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-17T06:15:36+00:00Added an answer on June 17, 2026 at 6:15 am

    Padding is being done in both cases. Inside the code you provided, char b requires no padding and thus receives none. int c requires two bytes of padding (I’m assuming typical x86 rules) and gets it. The total sizeof the struct is 10 bytes of data + 2 bytes of padding for the indicated 12 bytes.

    In the separate case, int b requires three bytes of padding and the struct as a whole requires another three to put char a on a 4-byte boundary address. 10 bytes of data + 3 + 3 bytes of padding give 16 bytes.

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

Sidebar

Related Questions

According to http://en.cppreference.com/w/cpp/string/byte/memcpy C++'s memcpy takes three parameters: destination, source and size/bytes. It also
Given is the snap shot of memory of a byte-addressable computer. What would be
Suppose that there are some hex contents in four-byte memory space. According to some
I need to write bytes of an IEnumerable<byte> to a file. I can convert
According to this post in Recursive Descent vs. LALR , any LALR(k) can be
Can anyone please identify is there any possible memory leaks in following code. I
According to some textbooks, the compiler will use sub* to allocate memory for local
I have a byte array in Java of size 4, which I am trying
**Here is a simple code of chat between two peers. According to me, the
I do not understand why the following is ambiguous according to compiler: byte x

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.