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

  • Home
  • SEARCH
  • 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 8192519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:11:58+00:00 2026-06-07T04:11:58+00:00

Possible Duplicate: Array index out of bound in C Can a local variable's memory

  • 0

Possible Duplicate:
Array index out of bound in C
Can a local variable's memory be accessed outside its scope?
C no out of bounds error

I am trying out this code snippet,

#include <stdio.h>

main(){
int a[2],i;
a[5] = 12;
for(i=0;i<10;i++){
    printf("%d\n", a[i]);
}
return 0;
}

It gives me output :

1053988144
32767
0
3
0
12
-1267323827
32716
0
0

Why a[5] is accessible ? Shouldn’t it through RunTime Error?

  • 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-07T04:11:59+00:00Added an answer on June 7, 2026 at 4:11 am

    int a[2]; means “allocate memory that is 2 * sizeof(int)“

    a[5] is syntactic sugar for *(a + 5), which point to an area of memory a + (5 * sizeof(int)). So 3 * sizeof(int) past the end of your array. Where is that? Who knows?

    Some languages do bound checking, and I have heard of some C compilers that can do it as well, but most do not. Why not do bound checking? Performance. And performance is a major reason for using C in the first place. But that’s OK, because C programmers are good programmers and never go beyond the bounds of an array. (hopefully)

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

Sidebar

Related Questions

Possible Duplicate: How can I index a MATLAB array returned by a function without
Possible Duplicate: Dynamic array in Stack? How do compilers treat variable length arrays Someone
Possible Duplicate: Multiple index variables in PHP foreach loop Can we echo multiple arrays
Possible Duplicate: Pythonic way to find maximum value and its index in a list?
Possible Duplicate: java - Array brackets after variable name When writing a Java function
Possible Duplicate: Sort multidimensional array by multiple keys I want know how I can
Possible Duplicate: php explode and array index In PHP 5.3... I have a dynamic
Possible Duplicate: Is there an equivalent of Array#find_index for the last index in ruby?
Possible Duplicate: Array memory allocation - paging Does byte[,] myArray is always in continuous
Possible Duplicate: Array slicing in Ruby: looking for explanation for illogical behaviour (taken 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.