Hello, and welcome.
In this lecture, I want to talk about how you can
display output to the screen.
So here I have our example program that we started out with.
And our first challenge was to display output to the screen.
And so after you look at this code, you probably noticed on
line 13, which is our printf.
This is the code that's actually displaying the output.
And again, this is a basic concept of c that needs to be addressed
very early on because you often need to display output to the screen.
So let's talk about displaying output to the screen using
this printf function.
Displaying output.
So again, I just mentioned this.
You should have noticed that printf line in our example
program, our first challenge.
It's included the word printf.
And you probably thought to yourself, what does this mean?
What does this do?
Well, now I want to explain it.
It basically displays output to the screen.
It's a standard library function.
And what are standard library functions?
We talked about this quite a bit, but it's a function that comes with
the c programming language that you can utilize to display output.
You would not want to write your own code to display output to
users because it's a very common thing that you do in your program.
So you wouldn't want to have to write that every time.
So what you do is you use that include directive.
You include the standard library header which defines that printf
function which allows you to display output to the screen.
Printf, specifically, is going to output information
to the command line.
Command line is also referred to as the console or the terminal.
But by default, it's actually displaying the information to
the standard output stream, which is the command line by default
that's why you see it there.
So you'll see it when we run our programs and we saw that little
black box the dos command prompt, the command line that's where
we saw our output because that's where printf is directing it.
We're saying display this output on the console.
The information displayed is based on what appears between
the parentheses of the function itself in the double quotes.
So everything inside those double quotes is going to display.
Now the printf function itself can get much more complicated
using format specifiers which we're going to discuss later.
But basic information is you just print out words and text.
And anything in between those double quotes is going to
be displayed to the output.
The other important thing to notice here and I mentioned in a previous
lecture is it's a statement so it's going to end in a semicolon.
The semicolon tells the compiler we're done, we're printing this
information now we're completed printing that information.
So the function itself it's probably the one of the most
common use functions in c because you often need to display output.
It will be the function that we use most most in this class because you
can use it for many, many things.
Now so far in our example first program we just displayed some text,
some output to the screen but it's very easy, it's very convenient
to also display program results besides just text inside quotes.
You can also display values of variables.
And the results of computations.
So what this means is it can be used for debugging, can be
used as a technique to display values of variables in your
program while it's running.
You can also use it to see where you are in your code as you're executing.
And this is one of the reasons I wanted to cover so early because
we're going to use it as a debugging technique so we can see what's going
on in our program as it's running.
And we're going to use it to display just regular words
and results of programs.
So it's very, very useful to understand how to display
output to the console using this printf function.
Again, the basic way to use is just include everything in
the double quotes, but we'll provide many examples of this.
I just wanted to tell you, hey, this printf, this is what it's doing.
It's displaying output to the screen and we're going to be using it quite a bit,
especially for debugging.
Thank you.