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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:24:05+00:00 2026-05-25T00:24:05+00:00

char * s; s[400] = ‘d’; If it’s not undefined behavior, then does it

  • 0
char * s;
s[400] = 'd';

If it’s not undefined behavior, then does it means I can’t arbitrarily access any part of my RAM outside the stack ? So each time an OS start a processus, it allocates a region of RAM where I can do nasty stuff (except mallocs), since the OS will clean the stack after the process finishes.

Why isn’t the OS able to clean the heap after the process ends ? Does it mean the heap is shared with all other processes ?

If I put too much data in the stack, it is a buffer overflow, but how much can I put in a stack ? Is it OS bound, RAM-size bound, or CPU-cache bound ?

  • 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-05-25T00:24:06+00:00Added an answer on May 25, 2026 at 12:24 am

    Yes, its behavior is undefined.

    s is not initialized, so s[400] is, at best, some indeterminate location in memory.

    EDIT:

    The last three paragraphs of your question have little or nothing to do with the two lines of code that we’ve been discussing. The undefinedness of s[400] = 'd'; has little or nothing to do with stacks, heaps, processes, or anything else. s is uninitialized, so it contains garbage; it may point anywhere in memory, or nowhere. s[400] is, at best, a char object located 400 bytes beyond the undefined location specified by the garbage address stored is s.

    If you understand that, you probably still have questions. I suggest posting a new question without the code sample.

    To partially answer some of what you’ve asked:

    Your program may not legitimately attempt to access any memory that’s not part of an object it has created (either by with an object definition like char foo[1000]; or by an allocation like char *ptr = malloc(1000);). In a particular implementation, there might be some region of memory outside any declared objects that you could get away with playing with, but there is no safe or portable way to do so — and no good reason. If you need to access some memory, allocate it first.

    The C language itself doesn’t even refer to the “stack” or the “heap”; those are implementation details.

    No, the heap is not typically shared between processes. Generally, all stack-allocated and heap-allocated memory is neatly reclaimed by the operating system when your program finishes. (The C standard doesn’t say this, since it only barely concerns itself with what happens outside the execution of your program, but it’s almost universally true, except perhaps in some embedded systems.)

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

Sidebar

Related Questions

{ char *a, *b; printf(%lx\n,(b-a)); } Usually works, in fact, I can't imagine it
char b; operator<<(cout,(operator>>(cin,b))); this is not compiling in vc++ because all 8 overloads cant
can somebody explain please, what exactly glutMainLoop does? and is the order of the
char first[10]; char second[10]; What does fscanf(fr,%s %s\n,first,second); do when first string is too
Char's are great because they are fixed size and thus make for a faster
char *strtok(char *s1, const char *s2) repeated calls to this function break string s1
char *values = 3 1 4 15; vector<int> array; I want to populate the
char myData[505][3][50]; //2D array, each 50 chars long char **tableData[505] = {NULL}; const char*
char c='c'; int i=10; double d =50; long l=30; String s=Goodbye; Are these statement
char* p = hello world; programmers usually assigns the address of an variable to

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.