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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:24:42+00:00 2026-05-25T01:24:42+00:00

struct s { int a; float b; int c; } How is this structure

  • 0
struct s
{
  int a;
  float b;
  int c;
}

How is this structure members stored in memory location?
My understanding is that when a structure variable is allocated then memory for the
structure members will also be allocated. If 1000 is the starting address then a will be at
1000, b will be 1004, and c will be 1008.

Integers and float will have different address spaces in the memory. How is a float and
an integer declared inside the struct represented in memory? Please help me to
understand.

  • 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-05-25T01:24:42+00:00Added an answer on May 25, 2026 at 1:24 am

    How is this structure members stored in memory location? My understanding is that when a structure variable is allocated then memory for the structure members will also be allocated. If 1000 is the starting address then a will be 1000 b will be 1004.will c be 1008.

    Since the size of int and even float is platform specific as is how structures are packed/stored/aligned/retrieved in memory, there is no platform neutral answer to your question.

    If it matters to you how structs are stored in memory, you’ll have to look into some compiler-specific ways to ensure structs are properly packed and aligned. For gcc see here for how to use __attribute__ to control packing and alignment. For MSVC see here for how to use pragma pack.

    Of course HERE BE DRAGONS:

    You’re venturing into the platform-specific way of how data is stored in memory, yarr there be many opportunities for bugs if you’re taking this hunk of memory and sending it off to another device. To prevent bugs (and there will be bugs) keep in mind:

    • Endianess.
    • If you’re casting to a pointer of another type (ie type-punning or aliasing) beware that C99 won’t support pointer aliasing. See the strict aliasing rule.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code struct Student { char name[48]; float grade; int marks[10,5]; char
Consider this piece of code: struct Trade { float Price; char* time; int shares;
Is there a side effect in doing this: C code: struct foo { int
I have this struct: struct Map { public int Size; public Map ( int
Say I have a struct s with an int pointer member variable i. I
I have this structure which I want to write to a file: typedef struct
Given a struct, e.g. typedef struct { int value; } TestStruct; Why does the
struct elem { int i; char k; }; elem user; // compile error! struct
Say I have some windows method and a struct: struct SomeStruct{ int foo; int
void addNewNode (struct node *head, int n) { struct node* temp = (struct node*)

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.