Apparently you are accessing memory to which you have read-access. Generally, there are no built-in safety nets with regards to e.g. reading/writing out of array bounds and other things alike - you just have to be careful.

@mitrmkar
>Apparently you are accessing memory to which you have read-access

Thanks for the reply. Well, does'nt dereferencing unallocated memory lead to memory access violation(which is what im doing).

Also i added this line:

a[-1] = 10;

which gave the following error:

Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted

What exactly does the above error mean?

>> Well, does'nt dereferencing unallocated memory lead to memory access violation

Not necessarily. Simply don't expect anything, that would indicate that something is seriously wrong, to happen.

>> Run-Time Check Failure #2 - Stack around the variable 'a' was corrupted
>> What exactly does the above error mean?

When you build a Debug configuration with /RTCs option on, the compiler inserts code that tries to detect stack corruption - this time you did an out-of-bounds write, which got detected.

See RTC (Run-Time Error Checks)

This question has already been answered. Start a new discussion instead.