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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:27:07+00:00 2026-06-13T20:27:07+00:00

Possible Duplicate: Why don’t I get a segmentation fault when I write beyond the

  • 0

Possible Duplicate:
Why don’t I get a segmentation fault when I write beyond the end of an array?

This code compiles and runs without any error. But how?

#include <stdio.h>

int main (void)
{
    int foo[2];

    foo[8] = 4; /* How could this happen? */

    printf("%d\n", foo[8]);

    return 0;
}

I’m compiling with GCC 4.7.2 on Arch Linux x86_64.

gcc -Wall -o "main" "main.c"
  • 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-13T20:27:08+00:00Added an answer on June 13, 2026 at 8:27 pm

    Because undefined behavior doesn’t mean “you will receive a segfault”, that would be defined behavior.

    Let’s assume you’re running in debug mode and your compiler is padding your stack/local variable space. You’re probably just writing into some unused part of the stack space.

    Build a release version on a Monday when your compiler is feeling cranky and now you overwrite the return address, or the code that sets up the call to printf, whatever. Oops.

    Just one possible outcome, but you get the idea.

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

Sidebar

Related Questions

Possible Duplicate: Why don’t I get a segmentation fault when I write beyond the
Possible Duplicate: PHP DateTime::days returns trash? Ok, I don't get this... Could someone explain
Possible Duplicate: What characters are valid in CSS class names? Don't if this is
Possible Duplicate: Ruby Assignment Syntax I don't get the concept of an assignment method
Possible Duplicate: How to get equivalent of ResultSetMetaData without ResultSet StringBuffer queryBuffer=new StringBuffer(SELECT *
Possible Duplicate: How do I get this CSS text-decoration issue to work? I'm using
Possible Duplicate: what's the point in malloc(0)? what does malloc(0) return? this code displays
Possible Duplicate: Process escape sequences in a string in Python If I get this
Possible Duplicate: Empty statement in T-SQL How can I get this to compile in
Possible Duplicate: Regular cast vs. static_cast vs. dynamic_cast I don't quite get when 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.