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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:49:06+00:00 2026-06-13T04:49:06+00:00

I have the following structure . Where the size is calculated on the side.

  • 0

I have the following structure . Where the size is calculated on the side. The size of the structure should be 30Bytes after padding . But the size is 28 . How is the structure size 28?

#include <stdio.h>
struct a
{
    char t;      //1 byte+7 padding byte      Total = 8bytes
    double d;    //8 bytes                    Total = 16bytes
    short s;     //2 bytes                    Total = 18Bytes
    char arr[12];//12 bytes 8+8+4+12=32.      Total = 30Bytes
};
int main(void)
{
    printf("%d",sizeof(struct a));  // O/p = 28bytes
    return 0;
}
  • 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-13T04:49:07+00:00Added an answer on June 13, 2026 at 4:49 am

    You can use offsetof to know the actual padding after each structure member:

    #include <stddef.h>
    
    printf("Padding after t: %zu\n", 
        offsetof(struct a, d) - sizeof (((struct a *) 0)->t));
    
    printf("Padding after d: %zu\n",
        offsetof(struct a, s) - offsetof(struct a, d)
        - sizeof (((struct a *) 0)->d));
    
    printf("Padding after s: %zu\n",
        offsetof(struct a, arr) - offsetof(struct a, s)
        - sizeof (((struct a *) 0)->s));
    
    printf("Padding after arr: %zu\n",
          sizeof(struct a) - offsetof(struct a, arr)
          - sizeof (((struct a *) 0)->arr));
    

    As R. wrote, you are probably on a 32-bit system where alignment of double is 4 bytes instead of 8.

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

Sidebar

Related Questions

gcc 4.4.4 c89 I have the following structure. struct device_sys { char device[STRING_SIZE]; int
I have the following structure typedef struct DeviceInfo { char[30] name; char[30] serial Number;
I have the following structure: class User include Mongoid::Document end class Resource include Mongoid::Document
Let's say I have the following structure declaration (simple struct with no constructor). struct
i have following structure: <td> <input name=foo size=45/> </td> And i want to dynamically
I have the following code (include-guards omitted for simplicity's sake): = foo.hpp = struct
In c, say you have the following structure and an instance of that: #include
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
Let's say you have the following structure in C#: struct Piece : IEquatable<Piece> {
I have the following structure [StructLayout(LayoutKind.Sequential)] public struct SFHeader { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)]

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.