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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:20:36+00:00 2026-06-11T20:20:36+00:00

This program creates and measures a struct with a pointer (8 bytes) and 3

  • 0

This program creates and measures a struct with a pointer (8 bytes) and 3 ints (4 bytes each) and shows there are 4 bytes of data padding.

I don’t understand why there are 4 bytes of data padding, either the CPU handles it 8 bytes at a time and there should be another 8 bytes of padding or it handles it 4 bytes at a time and there should be none right?

Or does it stick 2 4 byte values in an 8 byte section of memory and let the CPU split it up at runtime? (This would explain the discrepancy but it seems a bit inefficient to me)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct test {
    char *name;
    int age;
    int height;
    int weight;
};

struct test *create(char *name, int age, int height, int weight)
{
    struct test *thing = malloc(sizeof(struct test));

    thing->name = strdup(name);
    thing->age = age;
    thing->height = height;
    thing->weight = weight;

    return thing;
}

void destroy(struct test *thing)
{
    free(thing->name);
    free(thing);
}


int main(int argc, char *argv[])
{
    struct test * t1 = create("bleh",1,2,3);

    printf("Sizeof struct: %lu\n",sizeof(struct test));
    printf("Sizeof pointer (On 64bit system): %lu\n",sizeof(char *));
    printf("Sizeof int: %lu\n",sizeof(int));

    destroy(t1);

    return 0;
}

Output:

Sizeof struct: 24
Sizeof pointer (On 64bit system): 8
Sizeof int: 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-11T20:20:37+00:00Added an answer on June 11, 2026 at 8:20 pm

    The entire struct is probably padded at the end, for alignment reasons. This is needed since you might want to have an array of this struct.

    The padding you mention makes the struct always end up on an address which is evenly divisible by 8.

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

Sidebar

Related Questions

There is a program that creates a log file. This is an example of
This program creates five threads, each executing the function TaskCode that prints the unique
I have made a program that scans rss feeds. This same program creates feeds
use this website a lot but first time posting. My program creates a number
this program accepts user input and saved to a char array. Then creates a
I have a simple program which creates a thread, and waits when this thread
I understand there are many questions related to this, so I'll be very specific.
Hi so I am almost done with this program that creates the class minesweeper
This program creates a table of numbers, and then attempts to sum it up,
My program creates some threads for some tasks. My code is like this: Dictionary<int,

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.