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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:57:55+00:00 2026-06-08T18:57:55+00:00

Suppose, I wrote a function as follows: void foo() { char *strArr[] = {AA,

  • 0

Suppose, I wrote a function as follows:

void foo()
{
   char *strArr[] = {"AA", "BB", "CC"};
   ...
}

Where the strArr will be allocated? When will it be initialized?

For some reason I remember that such an array will be allocated in static memory space, not on the stack and initialized at the program start, as if I would write “static” before it. Is it a fake memory?

  • 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-08T18:57:59+00:00Added an answer on June 8, 2026 at 6:57 pm

    The array will be allocated as a local object. In general case, the memory for all local objects can be allocated early, when function begins execution, or it can be allocated “on demand”, as control enters the nested blocks with object declarations. The language does not specify the exact moment.

    In your specific example the memory for the array will be allocated when the function begins execution, since your array is declared in the “primary” block of the function.

    As for initialization… In C89/90 version of C all aggregate initializers have to be constant expressions, which means that the aggregate initialization process cannot depend on any run-time values. Initilization can be hardcoded into the compiled program and can take place immediately after the array is allocated.

    In C99 you can use run-time values in aggregate initializers, which means that the actual intialization might have to be delayed to the point when control passes over the declaration.

    In your example the array is initialized with constant expressions, meaning that it can be initailized immediately after allocation. The compiler can actually prepare a static copy of your array in advance and simply “paste” it into stack every time the control enters the function.

    P.S. Your references to “static memory” actually apply to string literals (like "AA") that you use to initialize the elements of your array. String literals indeed reside in static memory. However, string literals are completely independent objects, and your strArr array is a completely independent object.

    Note, that you don’t really have a “string array” in your example. What you have is an array of pointers to strings. Your strArr lives in local memory, while strings (to which elements of strArr point) live in static memory.

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

Sidebar

Related Questions

suppose i wrote my javascript in my aspx page like below <script type=text/javascript> function
I wrote a little javascript function that checks for a cookie when onFocus is
Suppose I write a function that takes no input but returns random variable e.g.,
Suppose that I want to write a case class Stepper as follows: case class
Suppose you write a function in SQL Server that conditionally calls itself. If you
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .
Suppose i have a function that returns an important result and several unimportant results.
I wrote init.d script that suppose to run java CLI proccess. The problem is
I'm supposed to write a wrapper function to MD5 hashing that restricts the input
Suppose I want to write an app for Android OS that is not going

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.