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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:09:35+00:00 2026-06-14T17:09:35+00:00

When you dynamically allocate memory e.g. malloc(1024 * sizeof(char)) the resulting pointer is set

  • 0

When you dynamically allocate memory e.g. malloc(1024 * sizeof(char)) the resulting pointer is set to NULL if there is not enough memory available to fulfill the request.

What happens when there is not enough memory to satisfy a static allocation such as char c[1024]?

  • 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-14T17:09:36+00:00Added an answer on June 14, 2026 at 5:09 pm

    char c[1024] is not necessarily a static allocation, it’s static or automatic depending if the declaration is written inside the body of a function (without the static modifier) or at top-level.

    A static allocation cannot fail at run-time because the space for the allocation is reserved as the program is being executed. If sufficient memory cannot be reserved, the program will fail to load (exec* will fail on Unix). In pathological cases the memory could be overcommitted by the OS, and the system will only reserve it once it is accessed. In that case, failure to allocate will result in the process getting immediately killed by the system.

    Automatic allocation simply moves the edge of the stack downward, typically by decrementing the stack pointer register. (This is why allocation of local variables is so fast.) A C program has no portable mechanism to detect that the stack has grown too large. Some operating systems will automatically grow the stack once the MMU detects that you have passed the allocated limit; Linux does this for the main thread, but not with other threads in a process. Even so, sufficient stack allocation will sooner or later surpass a system limit or will exhaust the memory of the system and the program will fail.

    Depending on the system, the program will either immediately fail with a segmentation fault or it will die from memory corruption which happens when the stack and the heap start meet.

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

Sidebar

Related Questions

I have a program and in there, I dynamically allocate memory by using malloc;
We know that malloc() and new operation allocate memory from heap dynamically, but where
I would like to dynamically allocate memory from the machine_init function in my arm
My project requires me to allocate memory dynamically. What am I doing wrong? /*Setting
What does the pointer of a dynamically allocated memory points to after calling the
I have code to dynamically allocate an array of 100 doubles to a pointer
When a C/C++ program containing the dynamically allocated memory(using malloc/new) without free/delete calls is
I'm trying to dynamically allocate memory for (what is essentially) a 2-dimensional array of
In Visual C++, I'm trying to dynamically allocate some memory which is 16-byte aligned
I read that pointers passed by malloc() & calloc() get allocated memory dynamically from

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.