indexoutofboundsexception - Why does non-existant array position allow compiling -



indexoutofboundsexception - Why does non-existant array position allow compiling -

#include <stdlib.h> #include <stdio.h> #include <ctime> // time functions #include <math.h> // pow() #include <iostream> using namespace std; int main() { int jiff=50; int sizes[jiff]; //array of size jiff sizes[49]=50; //existing, should lastly position sizes[55]=4; //should not exist printf("it %d\n", sizes[49]); printf("it %d",sizes[55]); }

output:

it 50 4

why doesn't code crash? sizes[55] should out of bounds , should crash @ run-time. gives?

edit: nevermind, crashes now, or prints out obscurely big numbers. new question: why not misbehaving earlier? first 5 runs flawless array position till 60

accessing memory not allocated causes undefined behavior. sometimes, might print whatever happens sitting @ memory address , might give segmentation fault. see this question list of mutual undefined behaviors

arrays indexoutofboundsexception

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -