can element be -ve value?

Feb 7, 2013 at 5:13am
Hi,
I have code in C :

tilt[0] = tilt[-tilt_step + 1];

my question, -tilt_step >> can element be -ve value? or it have another meaning?
Feb 7, 2013 at 5:37am
An array of N elements is indexed from 0 .. N-1

A negative index is going to throw exceptions.

So long as -tilt_step + 1 is >= 0 it should be OK.

Edit: So long as it's also < N

Jim
Last edited on Feb 7, 2013 at 5:38am
Feb 7, 2013 at 6:11am
Technically speaking... a negative value can be used legally... but you have to have a pointer that points into a buffer (not at the start of a buffer).


If your question is "can negative values be used like they are in python", then the answer is "no". As jim80y said.
Feb 7, 2013 at 7:18am
Thank you
Topic archived. No new replies allowed.