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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:17:28+00:00 2026-06-12T18:17:28+00:00

I guarantee that this question has been asked before, but I haven’t been able

  • 0

I guarantee that this question has been asked before, but I haven’t been able to find it via search; sorry in advance for any redundancies.

It’s my (potentially wrong) understanding that you only allocate to the stack when you know the size of an object at compile time. So in the case of initializing an array, you could do one of these (and this should go on the stack):

char charArray[50];

Since the size of this array is known at compile time, this should have no issues.

On the other hand, this (I believe) is also valid code:

char anotherCharArray[someVariable + 50];

Would this go on the stack as well? I am pretty sure the code segfaults if you free() this, so it makes me think it does, but it doesn’t really make sense to me. Similarly, is the 100% sole situation where you have to use free() when the data was allocated via malloc?

Thanks in advance for your help.

  • 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-12T18:17:29+00:00Added an answer on June 12, 2026 at 6:17 pm

    Similarly, is the 100% sole situation where you have to use free() when the data was allocated via malloc?

    Yes. (Apart from calloc and realloc, their return value is also to be free()‘d. Similarly, there are functions that use malloc() and this fact is documented, for example strdup() – the return value of these functions is also to be freed using free(), obviously.)

    char anotherCharArray[someVariable + 50];
    

    Would this go on the stack as well?

    Yes, it does (in most implementations – of course, it’s not always true that you assume, but on most of the platforms, it is). And yes this is valid code, but it is only standard in C99.

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

Sidebar

Related Questions

I'm sure this question has been asked and answered before, but my Google-fu is
I'm aware that this question has been asked a number of time on SO
This question has been asked again and again, but I have still a doubt.
This has been asked a lot of times already: I need to get the
I'm pretty sure that this is the right site for this question, but feel
Short question: Is it possible to map a buffer that has been malloc'd to
This question has been bothering me for a while. If I do int* a
Update: I can't delete this question, because the answer has been upvoted, yet it
This question seems to suggest that Ajax requests are not guaranteed to return in
I have a relatively simple question. Will using PHP guarantee that a form is

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.