- In this video we will continue our discussion
on the relationship between statements and expressions,
just to make sure you get a little bit more
exposure to the differences and how to
approach the process of building them.
An expression represents a single data item,
whereas a statement carries out some definite action.
It is not always wise to create
very complex statements.
When possible, it's better to break
the statements into smaller sub-statements
and build custom statements this way.
A simple expression statement is a = 6,
or c = a + b, or ++j;.
Compound statements are those that require
multiple steps of calculations
which result in a very specific action.
Let's go back to our code and see how this works.
Here again, we included the math.h library
and we start with simple statements without output.
Lines 20 through 24.
We are then following with a block of code,
line 25 all the way through line 34,
which is in green, and if you notice,
line 25 and 34 are comments lines.
Which means the entire block of code is being ignored.
Let's run this program and see what happens.
Oh, not much.
Everything below line 24 is commented out.
So there's really nothing that this program does,
other than printing a statement,
"These are simple statements without output."
Why would you want to do that?
When you have programs that deal with multiple
logical challenges, building expressions,
and any other compound issue, it is a good practice
to comment out portions of the code while you run the other.
This will give you an opportunity to ensure that
every piece of code runs correctly,
before you put everything together.
Now we're going to proceed and remove the comments,
save the file, and run this again.
This time, the calculations have been performed,
we calculated the area and the circumference of the circle.
Let's look at one more detail.
We included the math.h and notice that I am
no longer needing to define pi at 3.14, and so on.
Instead, on line 30, there is a
reference to M_PI, as well as in line 31.
This is the constant that's predefined
at the maximum available precision in math.h library.
This concludes our discussion so far on expressions,
statements, mathematical calculations, and formulas in C.
You are now ready to do a little bit more
advanced exercises and maybe even challenge yourself.