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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:40:55+00:00 2026-06-12T12:40:55+00:00

I have a char array as below: char buffer[100] And another char pointer as

  • 0

I have a char array as below:

 char buffer[100]

And another char pointer as below:

 char *buffer
 buffer = malloc(100)

When I use GDB to check out the stack pointer, they are actually different. Why?

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

    That is because the char buffer[100] will be allocated on the stack, which will occupy 100 bytes of storage. Therefore the stack pointer esp/rsp will point to a lower memory (taking stack grows downwards)

     +-    +------------+   <-- ebp
     |     |            |
     b     +------------+
     u     |            |
     f     +------------+
     f     |            |       holds 100 elements of buffer array       
     e     +------------+
     r          .
                .
     a          .
     r     +------------+
     r     |            |
     +-    +------------+  <-- esp
    

    And in the case of char *buffer only one char * type object’s memory (sizeof (char *)) will be allocated on the stack. When you do buffer = malloc (100) the base address of a memory block with 100 bytes guaranteed will be returned. This allocated memory is generally taken from the heap. Therefore now buffer holds the base address of the just allocated memory block. So, in this case because the memory is from the heap, and the stack only holds the char * type object, therefore the stack pointer is on higher location (taking stack grown downwards)

        +------------+   <-- ebp
        |   0xabcd   |             buffer , char * type
        +-----+------+   <-- esp
              | 
              |
              |             0xabcd 0xabce
              |             +-----+-----+-----+       +-----+-----+
              +------------>|     |     |     | . . . |     |     | 
                            +-----+-----+-----+       +-----+-----+
                                         0xabcf . . .
    
                            |                                     |
                            +------ 100 bytes mem block in heap --+ 
    

    Also note Richard J. Ross III’s comment.

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

Sidebar

Related Questions

I have a char type array[100] with 100 bytes stored in it. I want
I have a character array as shown below : char[] pwdCharArray = abcdefghijklmnopqrstuvwxyzABCDEFG +
I have a char array buffer that I am using to store characters that
I have 2-dimensional array like below. unsigned char myArray[][48] = { {0xfc,0x94,0x88,0x48,0x5f,0xa4,0x9a,0xfb,0x6e,0xf8,0xcd,0x01,0x47,0x64,0x03,0xd0,0x1f,0xb8,0xa3,0x85,0x84,0xa9,0x4a,0xc4,0x9e,0xea,0x26,0x09,0x62,0x96,0x91,0xa6}, {0xa9,0xc5,0x9a,0xb3,0x09,0x38,0x15,0xb3,0x22,0xb3,0x07,0x21,0x3e,0x39,0x35,0xc6,0x69,0x6e,0xf3,0x64,0xb0,0x0a,0x4c,0xcb,0x77,0xff,0x76,0x3c,0x37,0xf3,0x99,0x96}, {0x24,0x4d,0xc0,0x45,0xe0,0x50,0x1f,0x72,0x0f,0xb0,0xcc,0xb9,0xc6,0x72,0xa9,0x5a,0xf3,0x5a,0xd9,0xe2,0xc3,0x44,0xd9,0x25,0xf3,0x12,0x6a,0x0c,0x37,0x6a,0x3f,0xb6},
I am using apache.commons.net.telnet . I have char[] array . I am calling TelnetClient.getOutputStream().write(array[i]).
i have an char array b[20] which i want to write into a file
I have an char* array of binary data. It is binary media-stream encoded with
I have a char array in Python, which is read from a file e.g.
I would like to have a static char array member initialized in terms of
I have these methods. I have defined a char array in stringcontent.h file and

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.