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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:39:38+00:00 2026-05-28T14:39:38+00:00

Please tell me the difference between stack and heap with respect to below code

  • 0

Please tell me the difference between stack and heap with respect to below code

int main()
{
    int arr[3];
    int *a;

    arr [5] = 6; // out of bound but it will not give error.
    arr [3000] = 8 ; //SIGSEGV 

    a = malloc (sizeof (int));
    a[4] = 6; 
    a[4000] = 8; //No error
}

I know that arr is a static array and I am accessing some other process’s address when I do arr[3000] which gives SIGSEGV error. But I don’t understand why a[4000] will not give me any run time error i.e., SIGSEGV signal.

Thanks

  • 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-28T14:39:39+00:00Added an answer on May 28, 2026 at 2:39 pm

    It’s not guaranteed that any of those calls actually write to inaccessible memory (which would trigger a segfault). It’s just as likely that the program has permission to write to that memory and doesn’t trigger a segfault, but overwrites some other internal data unrelated to your array. This of course might lead to unexpected effects elsewhere in the program.

    Generally this is called undefined behavior. There are no promises made what happens when you write out of the bounds of the array, anything might or might not happen.

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

Sidebar

Related Questions

can somebody please tell me the difference between the following two code snippets: //Code
Could anybody please tell me what is the main difference between C & C++
Can any one please tell me the difference between target and currenttarget in flex?
could anyone please tell me, where in Javascript the difference between MyClass.prototype = new
Can somebody please tell me whether there is any difference between SPML and WSDL?
can you please tell me what is the difference between webservice and webapplication.
Could you please tell what is the difference between a WCF client and a
Hey, can anyone please tell me, what are difference between Dom parser and Xerces
can you please tell me the difference between the point and the arrow, for
Please tell me what is the difference in bash shell between launching a script

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.