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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:13:23+00:00 2026-06-11T12:13:23+00:00

why does the hexadecimal value of pointer address returned is always in decreasing order?

  • 0

why does the hexadecimal value of pointer address returned is always in decreasing order?
for example here int a was declared before int d, so it’s address always comes out to be greater than d, and same for &b,&e and &c,&f, I want to know that is this a fixed behavior or is this compiler dependent?
I am using gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-1)

#include<stdio.h>

int main(void){
    int a=1;
    int d=1;
    char b='a' ;
    char e='a';
    float c=1.0;
    float f=1.0;
    printf("a=%p\nd=%p\nb=%p\ne=%p\nc=%p\nf=%p\n",&a,&d,&b,&e,&c,&f);
   if (&a>&d)
        printf("&a>&d\n");
    else
    {printf("&a<&d");
    }
   if (&a>&d && &b>&e && &c>&f)
       printf("addresses are in descending order");
   else{
       printf("false");
   }

  return 0;

}

output:

a=0xbfc6bd98         //a>d
d=0xbfc6bd94         
b=0xbfc6bd9f         //b>e
e=0xbfc6bd9e
c=0xbfc6bd90         //c>f
f=0xbfc6bd8c
&a>&d 
addresses are in descending order

PS: I am new to c

  • 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-11T12:13:24+00:00Added an answer on June 11, 2026 at 12:13 pm

    Found this nicely explained in Smashing The Stack For Fun And Profit, by Aleph One.
    Extracted the most relevant parts.


                             /------------------\  lower
                             |                  |  memory
                             |       Text       |  addresses
                             |                  |
                             |------------------|
                             |   (Initialized)  |
                             |        Data      |
                             |  (Uninitialized) |
                             |------------------|
                             |                  |
                             |       Stack      |  higher
                             |                  |  memory
                             \------------------/  addresses
    
                         Fig. 1 Process Memory Regions
    

    […]

       The stack consists of logical stack frames that are pushed when calling a
    function and popped when returning.  A stack frame contains the parameters to 
    a function, its local variables, and the data necessary to recover the 
    previous stack frame, including the value of the instruction pointer at the 
    time of the function call.
    
       Depending on the implementation the stack will either grow down (towards
    lower memory addresses), or up.  In our examples we'll use a stack that grows
    down.  This is the way the stack grows on many computers including the Intel, 
    Motorola, SPARC and MIPS processors. 
    

    […]

       Let us see what the stack looks like in a simple example:
    
    example1.c:
    ------------------------------------------------------------------------------
    void function(int a, int b, int c) {
       char buffer1[5];
       char buffer2[10];
    }
    
    void main() {
      function(1,2,3);
    }
    ------------------------------------------------------------------------------
    

    […]

    With that in mind our stack looks like this when function() is called (each
    space represents a byte):
    
    
    bottom of                                                            top of
    memory                                                               memory
               buffer2       buffer1   sfp   ret   a     b     c
    <------   [            ][        ][    ][    ][    ][    ][    ]
    
    top of                                                            bottom of
    stack                                                                 stack
    

    As you can see, new (local) variables are pushed on top of the stack. Depending on the design of the architecture the stack grows towards higher memory addresses or towards lower memory addresses, the latter in your case.

    From the viewpoint of the C language specification the order of memory locations of subsequently allocated variables is unspecified. Therefore, it depends …

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

Sidebar

Related Questions

How does one obtain the complementary hexadecimal value for a given input ? This
I am trying to pass a Hexadecimal color value from objectiveC to Javascript. I
Does anybody know, whether it's possible to output the values in a hexadecimal via
System.Xml.XmlException: Name cannot start with the character 9, hexadecimal value 0x39 Is this because
Does anybody have a Unicode to Hexadecimal code points (as seen in the link
How does one convert a string of colon-separated hexadecimal numbers into a ctypes array
In C++, to print a number in hexadecimal you do this: int num =
Is there any way by which we can directly convert a hexadecimal value to
Does anyone know if there is a way to generate different code in the
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP

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.