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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.31 Forme abbreviate di assegnamento<br />

Dal momento che alcune forme di assegnamento sono molto comuni, esistono delle forme abbreviate<br />

<strong>per</strong> l’assegnamento, realizzate dai seguenti o<strong>per</strong>atori:<br />

Esempi<br />

o<strong>per</strong>atore *= /= %= += -= = &= ∧ = | =<br />

op uguale (dove op vale: asterisco – slash – <strong>per</strong>centuale –<br />

più – trattino alto – doppio minore – doppio maggiore – “e”<br />

commerciale – accento circonflesso – barra verticale)<br />

sintassi espr1 op= espr2<br />

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

utilizzo sono forme concise di expr1 = expr1 op expr2<br />

associativita’ ⇐=<br />

commutativita’ NO<br />

m = s / 60; s %= 60; /* da secondi a minuti e secondi */<br />

flags |= FLAG_BUSY; /* alzo un bit */<br />

flags &= ~FLAG_BUSY; /* abbasso un bit */<br />

La seconda istruzione della prima riga equivale a s = s % 60, mentre le altre due sono<br />

equivalenti rispettivamente a flags = flags | FLAG_BUSY e flags = flags & FLAG_BUSY.<br />

Infine, le tre istruzioni seguenti sono equivalenti:<br />

i = i + 1;<br />

i++;<br />

i += 1;<br />

6.32 O<strong>per</strong>atore virgola<br />

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

virgola<br />

sintassi espr1 , espr2<br />

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

utilizzo valuta l’espressione espr1 ignorandone il risultato, poi valuta<br />

l’espressione espr2 che vale come risultato dell’o<strong>per</strong>azione<br />

“virgola”<br />

associativita’ =⇒<br />

commutativita’ NO<br />

E’ usato principalmente nei cicli while e <strong>per</strong> fare cicli for con due o più indici.<br />

74

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

Saved successfully!

Ooh no, something went wrong!