hello, i made a selection sort program using for loops not functions,the array can only store 10 elements, out of curiosity i entered more than 10 elements to be sorted an it works. can some one please explain this to me , how is that possible .
hello, i made a selection sort program using for loops not functions,the array can only store 10 elements, out of curiosity i entered more than 10 elements to be sorted an it works. can some one please explain this to me , how is that possible .
So you have an array and the compiler knows that this is memory that belongs to you. There is a lot more memory, which has not been allocated to you, but it's still accessible. What you are essentially doing is writing and then reading from that memory without having specifically asked for it. You *can* do that, but note that this isn't safe and should never be relied upon. The compiler can choose to re-order your variables and then your program will most likely crash if you try to enter more than 10 elements.
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
C and C++ do allow this; you are not protected though. By doing what you are doing and to emphasis what QuantumPete stated you are stepping into a world of undefined behavior.