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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:16:26+00:00 2026-06-11T22:16:26+00:00

If I allocate memory for a char a[256] , initialise each element to a

  • 0

If I allocate memory for a char a[256], initialise each element to a different value and pass this to some function:

int subFunc(a);

how does the stack frame of subFunc look?

Does the stack frame contain all the 256 bytes in it or just a pointer to the address of a (4 bytes).

If a pointer, then how does it access the data inside the subFunc or where is this data available to subFunc?

  • 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-11T22:16:27+00:00Added an answer on June 11, 2026 at 10:16 pm

    subFunc will receive a pointer to char, not an array of char. The details of how that pointer is passed will vary with the implementation. The pointer value may be pushed onto the stack, or it may be passed in a register (gcc 2.96 on Red Hat does the former, while gcc 4.1.2 on SLES 10 does the latter), and that may depend on things like optimization settings, whether you’re generating a debug version, etc. The only way to know for sure how it works on your platform is to code it up, build it, and look at the generated machine code.

    In most circumstances, an expression of type “N-element array of T” will be converted (“decay”) to an expression of type “pointer to T“, and the value of the expression will be the address of the first element of the array. The exceptions to this rule are when the array expression is an operand of the sizeof, _Alignof, or unary & operators, or is a string literal being used to initialize the contents of another array in a declaration.

    Given the code

    char a[256];
    ...
    subFunc(a);
    

    the expression a in the call to subFunc has type “256-element array of char“; by the rule above, it is replaced with an expression of type “pointer to char” (char *) and its value is the address of a[0].

    Thus, subFunc receives a pointer value, not an array of char.

    Note that, in the context of a function parameter declaration, T a[] and T a[N] are interpreted as T *a; if your prototype for subFunc is

    int subFunc(char a[256])
    

    it will be interpreted as

    int subFunc(char *a)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to pass a pointer to pointer to a function, allocate memory in
I'm trying to allocate some memory for a char* as follows. static ssize_t memo_write(struct
How do I allocate memory for a char variable (not a char pointer) inside
I would like to dynamically allocate memory from the machine_init function in my arm
Which is preferable way to allocate memory for a function that is frequently allocating
I've read that mysql_store_result() in the MySQL C API will allocate memory for each
When I allocate memory on a specific NUMA node using numa_alloc_onnode() like this :
Assume the following situation: typedef struct { int ID1; int ID2; char string[256]; }
Is allocating a buffer via new char[sizeof(T)] guaranteed to allocate memory which is properly
For the getline() function, I tried two method to allocate memory space for 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.