Hello and welcome.
In this lecture I want to basically highlight some of the concepts for a C program.
I want to describe the structure of a C program.
We're going to talk about the details of all the syntax and so forth in other lectures.
But I want to describe at least some of the things you saw in your challenge, just some of the highlights.
Again, we're going to go through other concepts in more detail.
And so you remember this.
This looks familiar.
I just wanted to show you a little bit about the structure of this code.
We'll talk about, include statements and so forth.
But one of the important things to to understand in this this program right here is this is kind of
the basic structure for all C programs.
The first thing you should notice here is this this code on line three, which is called Main.
It says Main there and it has two parentheses.
Those two parentheses are signifying that it's a function.
Now, we don't know what a function is yet, but basically a function contains code inside of it.
And so I want to describe to you that the main function is part of all C programs.
It's the entry point to the program.
This is what gets invoked when you run the program.
Everything inside line four to line seven will be executed.
Okay.
And so this main function is a special function in C that gets invoked when you execute the program.
And you know, it's a function because it has parentheses and functions is just a way to organize your
code.
The things that you should notice here is on lines four.
You have a squiggly bracket left, squiggly bracket, and on line seven you have a right squiggly bracket.
This defines the starting of the function.
And then on line seven, the ending of the function.
This is referred to as a block of code.
So lines five and six is the block of code inside the function main.
And again, I want to reiterate main is a special function in C that gets invoked when you run the program.
So there should be at least one main in all C programs and only one main.
Now I'm going to show you how to structure the program with other functions.
But this is a basic program, so it contains our main function and this gets invoked.
And then in lines five and six, this is the body.
This is the block of code for the function main.
And you'll notice four and seven, start and end those functions.
So what I'm trying to tell you here is blocks of code in this idea of functions.
These are all.
Part of a structure of a C program.
Other things to notice here is C programs are case sensitivity matters.
So whether you use uppercase or lowercase, it's going to make a difference.
So if I were to change this, I an int to an uppercase I it's not going to compile because that's an
error.
And when I said earlier that you have to pay attention to the details, I meant it.
Every little detail in a program can cause a problem or cause an error.
So case sensitivity matters, uppercase, lowercase, it makes a difference.
The other important thing to notice here is in the uppercase and lowercase, by the way, are distinct.
It doesn't.
And also here, when we edit our source code, it doesn't matter where you start typing your line,
you can type it at the beginning, you can put everything on the same line if you want some of it.
However, I will explain that it makes it easier to read if you do some kind of structure to it.
But you can do things.
Do that if you want to.
The other thing that's important to note here, that's not a specific concept is that all the statements
are ending in a semicolon.
So that's a syntax detail that you have to understand.
Now, lines three and four and line one, those aren't statements of code three is defining a function
for specifying the start of the function.
One is doing something different.
It's including some library that you want to use in your code.
But Lines five and six have semicolons because those are statements and we'll talk about statements
and so forth.
But you do want to recognize that a semicolon is also important.
All right.
And other concepts that I'm going to explain.
I'll explain line one.
I'll explain functions in a much more detail.
I'll explain why there's an int on line three.
But really wanted I wanted to point out here is the structure of blocks of code and functions and this
idea of the main function being the entry point of the C program.
So this simple C program is you're going to see very similar things in all programs.
You're going to see that main routine and you're going to see brackets for functions.
And that's really how programs are going to be organized.
Now, this function may call other functions.
That's a whole other ballpark.
But again, I want to emphasize here the idea of blocks of code inside functions and also this idea
of the main routine and then the semicolons that end.
Now, the other thing here that you'll notice is I did indent certain pieces of code and we'll probably
talk about this more when we talk about quality of code.
But you want to make your code readable.
And what readable code means is if I were to just write my code like this and I would have placed things
on the same line.
It makes it a lot harder to read, doesn't it?
You see how that's a lot more difficult to follow?
But when I add new lines and I add indentation after each line of code, it makes it easier to read.
You can easily identify that lines five and six are inside of a block of code because it has the brackets
and there are specifically inside of a function called main.
So the use of indentation spacing new lines in meaningful names will make your code more readable.
That's the other takeaway for your first program.
I mentioned other.
The main takeaways for the structure of a program and readability is another important one.
But this is just describing, again, the structure of a C program that you'll see in all C programs.
In the next few lectures.
We're going to talk about some of the basics of C.
I'm going to describe to you this idea of the include statement, this concept of displaying output
using a printf, the idea of returning data from the main, all these nice little concepts that are
sort of really common for programs.
They're not a specific category.
They're really just fundamentals and we'll be describing that in the next few lectures.
Oh, and one other thing, just to give you a little heads up, this is going to be discussed in more
detail, but other things that you may notice that sometimes students ask about is what's going on with
this.
INTEGER Right?
And when we talk about function, we'll talk about how you can return data from a function.
But this basically just means you have to have a return.
And this is saying that the main function is going to return a number.
And what this usually represents is whether or not there was an error in the program.
So when you return zero, it means that there was no error in the program.
If you return an error code like 44, that might represent an error in the program.
But again, we'll talk about that.
More functions, but be understanding of this keyword INT and you won't always see the int there.
There are times when you'll see a void keyword there and again, that's okay as well.
That just means that the, the main function doesn't return any data.
You might get a compiler warning for that, but typically you'll see int But it just means it's returning
something.
Sometimes in the main you'll see this keyword named void, and this just means that the main program
doesn't accept any parameters or any data.
Again, these are terms we use when we talk about functions, but when you see these things, don't
worry about too much right now.
They'll be explained when we talk about functions.
But you do see void.
Void is just another way to say no data.
It's not required.
It's pretty much the same with empty parentheses now because the main is a keyword.
You can't declare variables named main that will give you an error, things like that.
Just a couple gotchas that you want to be familiar with.
Again, questions I get asked often why is there an int there for the main function?
Why is sometimes I see a void?
Why do we return data?
Why do we return a zero?
That's why.
For error codes.
Thank you.