- By now you're probably anxious to start coding.
So, we're not gonna postpone this any further.
Let's talk a little bit about our first C Program.
As we just recently showed you,
before you get down to writing code,
you need to have a plan.
In this case, the plan is to show you
how to write a very simple program
that will ask the user to enter a number
and then we'll print back that number.
Let's switch no to the IDE and see how this program works
and we'll talk as we look at the program,
at the code, what some of the things do
and what will be the best approach for it.
This program is intended to do a
very simple thing.
It asks the user to enter a number.
We want the user then to type that number
and the program will then print the number back.
As you can see on the right hand side here,
in green, there are comments.
Comments are not part of the program.
They're just text intended to explain
certain lines of code.
We will spend more time later on
talking about what is a comment,
where should it go, what should it say.
Let's focus on the code.
Without getting into all the details,
what every command does and why it is there,
let's focus on the main things that
we wanted this program to do.
As we said, we had a plan.
Our plan was to tell the computer
to ask us a question.
This line right here, please enter a number,
it's a hint that probably this
is where this will happen.
You can infer, even if you don't know C,
that the command like print, probably prints something.
It may not be intuitive to you,
that a command like scanf asks
someone to enter a number.
Scans comes from the word, scan for an input.
Finally, after the user receives the instructions
to enter a number, and types a number,
the computer will again print you enter that number.
There are other things that go in here,
as I said, we're not gonna focus on right now.
So, let's put this to test.
First we're going to build this project,
if it's not already built.
Built finish, we know that everything
was smooth and no errors.
And now we can run it.
As you see the program asks me to enter a number.
So, I will enter a number, and hit enter.
The computer tells me I entered 345.
Everything works flawlessly.
The program does exactly what I instructed it.
But, let's try something else.
Let's run the program again,
and what if I don't type a number?
What if I type some letters?
Let's see what happens now.
Ah ha, I didn't expect that.
We'll talk about this later.
I'll just mention one thing.
Whatever you think is a letter or a number,
it's all in your head.
To a computer, everything is number.
No just numbers, but binary numbers.
We'll get into this much later.
One thing to note right now,
C assumes you know what you're doing.
It will not tell you, other than illegal grammar usage,
it will not tell you anything about your style,
or what you meant.
It will not second guess you.
Sometimes in computer science,
we want to call this G I G O or gigo.
Which stands for garbage in, garbage out.
If you gonna write code that's garbage,
it will create garbage.
It's a term commonly used by most
programmers and in industries as well.
Well, now you have your first C program, that works,
as long as you give it exactly what it asks you.
If you try to be smart, it'll outsmart you.