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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:34:20+00:00 2026-05-26T11:34:20+00:00

I’ve been learning about C recently, and I’ve encountered something which I can’t seem

  • 0

I’ve been learning about C recently, and I’ve encountered something which I can’t seem to find a good answer to.

In my code I might have:

struct randomStruct a;
struct secondStruct array[5];
struct structyStruct q = { 17, "Hey yo", {123,123}};

But in memory, they might be stored as:

q, a, array

What I mean here is that q’s adress in memory is lower than a’s, which is lower than array’s.

What determines the order in which variables are saved in memory?

(If you need more information/actual runnable code, please let me know)

Thanks in advance!

  • 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-26T11:34:20+00:00Added an answer on May 26, 2026 at 11:34 am

    The C standard specifies the memory order of items within a struct, and many (perhaps all) implementations explicitly specify the memory order of parameters to variadic functions, but the order of automatic and static variables should be regarded as something which a compiler may arbitrarily or randomly arrange without rhyme or reason. Many compilers use a hash table for identifiers, and at least some compilers would arrange variables according to their hash codes, which made variable placement effectively random.

    Further, some processors are designed so that certain variable placements will yield faster execution than others. For example, a compiler for a certain microcontroller may determine that placing two variables within 256 bytes of each other will allow it to load the address of one into a register and then use short-displacement register-relative addressing to access both; even if today’s compiler wouldn’t make that optimization, there’s no reason to believe tomorrow’s won’t.

    If you care about the relative arrangement of variables in memory, then you must either mark the variables in a vendor-specific way (typically using #pragma directives) to control how they are placed in memory, or else place all variables of interest into a struct. In some cases, it may be helpful to use #define macros to allow the struct items to be referred to by what look like variable names; the biggest caveat with doing this is that #define macros do not obey any normal rules of scope; consequently, one must be certain that the “variable” names are not used as any sort of identifier anywhere in the program.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string

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.