This question already has answers here:
The C language has the concept of
undefined behavior. It means the language doesn't prevent you from doing things you aren't supposed to do, but if you do there's no guarantee what the program will do afterwards.
It may crash, it may output strange results, or it may appear to work normally. How undefined behavior manifests itself can change if you make a seemingly unrelated code change, such as adding an unused local variable, adding a
printf call for debugging purposes, or compiling with different optimizations settings.
In this case, you got "lucky" that nothing bad seemed to happen. Someone else running the same program may get different output from you because you wrote past the end of the array.
When I ran this code I got the following output:
Enter number of elements which you want to append :6
Enter the values :1
*** stack smashing detected ***: ./x1 terminated
1 2 3 4 5 6 7 Aborted (core dumped)
How do Dynamic arrays work?, Also, we can reduce the size of the array. and add an element at a given position, when required added some more element in array then use this approach: an element from end, simply store zero at last index and you also delete element A LinkedList can handle as many elements as you can represent in memory. Or you could implement your own list type. Or you could implement your own list type. Indeed, you could even implement a list type that can hold more elements than you could store in memory or even an unbounded number of elements if your list is actually a generator.
This code results in undefined behaviour because, there is an attempt to access elements outside of array. There are two options to overcome this issue:
block[X] - X should be defined with fixed size. Value provided by user should be compared with X - then You are sure, You are not jump outside of array size.
block[X] - array is created dynamically with X provided by user (check malloc() function)
Array Basics, An array is an indexed collection of data elements of the same type. to the form of a normal declaration (typeName variableName), but we add on a size: are used to store C-style strings, you can initialize a character array with a string literal (i.e. It is illegal to use a set containing more elements than the allocated size. C program to insert an element in an array, for example, consider an array a  having three elements in it initially and a  = 1, a  = 2 and a  = 3 and you want to insert a number 45 at location 1 i.e. a  = 45, so we have to move elements one step below so after insertion a 
In C arrays don't have boundary check. You have array of int it's width is 5. It doesn't stop at only five elements if you add more than five elements to the array that is undefined behaviour.
It's user responsibility to make sure array boundaries doesn't exceed than allocated.
Object-oriented Data Structures Using Java, We need the queue items themselves; they are the elements of the underlying array. The capacity variable holds the maximum number of items the queue can hold, and the numltems There are several alternatives possible. we began by inserting an element into the first array position and then we let the top float with Why do we do stuff = [ ] before using an array? This creates the variable and lets Python know it is an array. The ___________ method adds a new item onto the end of the array.
Data and File Structure (For GTU), 2nd Edition, Before we insert a new element in the queue, it is necessary to test the condition of when Rear is equal to the MAX-1, where MAX is the maximum size of the array. by the Front is assigned to a local variable and then Front is incremented by one. Rear and Front store the indices of the rear and front elements of Queue. Because an array can contain multiple elements, in code you can use a(n) ____ to reference each element of the array. Loop A ____ statement can be used to catch exceptions, such as an IndexOutOfRangeException. Ivor Horton's Beginning Visual C++ 2005, You can find the index position where it should be inserted with these You can now copy the names array into a new array that has one more element and You then copy all the elements from the old to the new up to index position of dimensions an array can have is 32, which should accommodate most situations. You can create an array with elements of different data types when declare the array as Object. Since System.Object is the base class of all other types, an item in an array of Objects can have a reference to any other type of object. In order to retrieve different data types from an Object array,
Data Structures 101: Arrays, Arrays are very powerful data structures that store lists of elements. If you need to access more than one of them, the process is extremely optimized Let's say that you define an array of size 5 but only insert one value. An index of the first element (default to 0) is called the lower bound, and an index of the last element is called the upper bound of an array. The figure illustrates the array. Array Representation Access Array Elements. We can add, insert, update and access values using index, as shown below.
Comments C language is giving the programmer almost the full freedom, even if something is against the rules of the language (like writing outside the array bounds). You can, but the language itself does not guarantee what will happen with the program. It is called Undefined Bahavior which may be a great but dangerous tool in some circumstances or the curse in other (actually 99.99% of the cases or 100% for beginner programmers) Every night at 3am I walk from my house to the all-night diner across the street. There's a Walk / Don't Walk sign at the intersection, but there's never any traffic, and I got tired of waiting, so I started crossing even though the sign says Don't Walk. Nothing bad ever happens. What's the point of having the Walk / Don't Walk sign if I can cross whenever I like? Please use the linked canonical duplicate for FAQ questions like this. I think this was the 3rd "why can I access the array out of bounds" question today alone. This is not OP is asking. So, in your opinion... What OP is exactly asking ? I have answered like the others - it is UB. It clearly states, "If that's the case, then why even declare a size for the array?", and now read your answer. Ok, main post have been edited - now with the proper question. I will not repeat more detailed answers that have been already posted. To be fair with you, I have made a negligible edit in your answer so that I can retract down-vote. It isn't your fault anymore.