Doubt in my code

Hello, here is my code which I have used in visual studio code as well

But my problem is little bit different. When I use this code on coding blocks online ide it works well but when I run it on my visual studio code it prints some weird value looks like garbage value. Why it is happening ?

hello @yashsharma4304
image
for i =0 , u r trying to access negative index.
by default cb compiler gives 0 for negative index access but some compiler may give some garbage value hence the weird result.

to avoid this simply put one if statement and handle i=0 case seprately

1 Like

Ok thanks a lot for you help. Today I learned a new thing :slightly_smiling_face:.

by default cb compiler gives 0 for negative index access

but its not good practice, always avoid negative index access

1 Like

Ok I will avoid it :v: