- Statements and expressions are some of the
fundamental building blocks of every computer program.
In fact in C a lot of those expressions
relate to mathematical formulas,
and it's not surprising given the
deeply rooted foundation in math that C has.
For example, anything that has
to do with variables, constants, and operators
this is language directly borrowed from mathematics.
Things like 25+12.
Or x^2
or length x width.
In fact C married to your computer
it's an awesome calculator.
Everything you can do with one of those
fancy graphic calculators you can actually program in C
and have your computer do the same.
Statements are code elements that execute an action.
Statements are actually expressions
put together into a formula that calculate something.
For example, age = todayDate - birthdayDate;.
Here's another little bit more complex expression.
If you have not learned yet in C
but try to read through the words.
If (age > 17) canDrive =TRUE;?
Those two are example of statements
and many more that you will see shortly.
In this code we see different ways
in which you can type expressions
and make statements with those expressions.
For example, you can define on Line 16
a variable days and immediately assign it
a value that's a result of a computation.
In Line 17 and 18 you're creating just simple
expressions in which you assign initial values
to variables for later on to be used
in a more complex statement.
This may be simple but it actually has a practical use.
Calculating the perimeter of an object assumed
the formula to be 2 x width + 2 x height which
I explicitly wrote as width + width + height + height.
Since the width and height are given
we can now calculate the perimeter and print it.
And lets see how this works.
Build a project and we run.
And lo and behold the perimeter is 46.94.
I could easily change this number
to something else should I want
to calculate another perimeter.
And all I have to do is hit run,
click Yes, and here's my new perimeter.
However what happened here it did
not recalculate the new value because
there's another step which we will learn shortly
that requires an additional building of the project.
So one of the things to keep paying attention to
is that when you make a single change
not everything happens behind the scene
as you would expect.
So it requires a little bit further digging
and investigation into learning how
the IDE and the C language work.