Getting Started

(lily) #1

Chapter 4: C Types, Operators, and Expressions


e can then use PI anywhere in our software and the compiler will automatically

erence = 0.0;
us = 0.0;

iePanRadius^2);

ecla


ent that declares to the complier how your words are
d char counter = 0’ you are telling the
mpiler that when it encounters the word ‘counter’ to consider it as data stored at
me specific location with the alias name ‘counter’ that can have values from 0
lue of 0.

algebra often enough that you need to
think they should. The compiler
than what you wanted it to do.
sion you can run into when you use the ‘=’
ssignm operator:

= y;
lay_loop_2(30000);

. The second calls the
about:


_loop_2(30000); //BAD STATEMENT

elay_loop_2(30000) function. The
’ bec use the condition, x=y, is always true, so the delay
VR compiler will think something is strange and issue
is warning:

round assignment used as truth value

W

substitute the numerical value for it:


float pieCircumf
float piePanRadi


pieCircumference = PI * (p


D rations


A declaration is a text statem
to be used. When you declare ‘unsigne
co
so
to 255, but in this case initially has a va


Arithmetic Operators.....................................................................................


Operators seem like ordinary arithmetic or algebra symbols, and they mostly are.
But they are different from arithmetic or
pay attention when operations don’t act like you
might just be doing what you told it to do, rather
An example of the kind of confu
a ent operator and the ‘==’ ‘is equal to’


x
if(x==y) _de


The first statement assigns x to the value of y
_delay_loop_2(30000) function if x is equal to y. What


if(x=y) _delay


This will set x equal to y, and then call the _d
‘if omes meaningless beca
will always run. The WinA
th


Warning: suggest parentheses a
Free download pdf