18.08.2013 Views

Dalla A alla Z passando per C - Robotica

Dalla A alla Z passando per C - Robotica

Dalla A alla Z passando per C - Robotica

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.13 Incremento e decremento<br />

o<strong>per</strong>atore ++<br />

più più<br />

sintassi val++ oppure ++val<br />

n. o<strong>per</strong>andi 1<br />

utilizzo incrementa di una unità il valore di val<br />

associativita’ ⇐=<br />

commutativita’ NO<br />

o<strong>per</strong>atore −−<br />

meno meno<br />

sintassi val−− oppure −−val<br />

n. o<strong>per</strong>andi 1<br />

utilizzo decrementa di una unità il valore di val<br />

associativita’ ⇐=<br />

commutativita’ NO<br />

Si tratta di o<strong>per</strong>atori con un solo o<strong>per</strong>ando; se l’o<strong>per</strong>atore sta dopo l’o<strong>per</strong>ando (esempio: i++)<br />

l’incremento o decremento viene fatto dopo aver usato il valore dell’o<strong>per</strong>ando, se l’o<strong>per</strong>atore sta<br />

prima dell’o<strong>per</strong>ando (esempio: ++i), l’incremento o decremento viene fatto prima di usare il<br />

valore. L’o<strong>per</strong>ando deve essere assegnabile (si veda la discussione su “lvalue” nella Sezione 6.30<br />

sull’o<strong>per</strong>atore di assegnamento).<br />

/* stack pointer che punta al primo elemento vuoto */<br />

int stack[10], sp = 0;<br />

/* inserimento ("push") */<br />

stack[sp++] = datum;<br />

/* estrazione ("pop") */<br />

datum = stack[--sp];<br />

i = 10; while (--i) {<br />

/* ciclo <strong>per</strong> i che varia da 9 a 1 */<br />

}<br />

i = 10; while (i--) {<br />

/* ciclo <strong>per</strong> i che varia da 9 a 0 */<br />

}<br />

60

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!