Akash
Akash

Reputation: 5012

Negative index for array in cpp

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

Answers (1)

Bill Lynch
Bill Lynch

Reputation: 81916

You're correct. This code is invalid because it is dereferencing memory outside of that array.

Upvotes: 2

Related Questions