Reputation: 5012
while browsing through a queue examples, I came across
http://login2win.blogspot.in/2008/07/c-queues.html
Its a queue example in which the indexes start from -1, but the program seems to be working fine
Is this valid, shouldn't this be a undefined behavior in some cases?
Upvotes: 1
Views: 204
Reputation: 81916
You're correct. This code is invalid because it is dereferencing memory outside of that array.
Upvotes: 2