Hello and welcome back.
In this video, we're going to create our first C program.
And so you're probably familiar with this view.
This is called light.
We have a couple projects in this workspace from previous videos, Project two, Project three.
We want to create a new project and we should know how to do this.
At this point, we can just go up to file new new project, or we can select the workspace right click
and say New project.
This will bring up our new project Wizard.
I'm going to use the previous template that we created from a previous video, and so I'm just going
to name this project, our first project.
How about our first program?
That's even better.
And in the category, I'm going to actually select our user templates.
And for the type, I'm going to select my template, I'm going to hit.
Okay.
And you'll notice that it now created our first program folder, but it's not highlighted bold, it's
not bold.
We have to make that bold meaning our active project, because that means whenever we edit it or compile
it, it will actually compile this project.
So we're going to go ahead and we're going to double click that to make it bold.
So we select Main.c and we're going to close that other file and you'll see that we have our templated
Hello World program from our previous project settings.
We're going to go ahead and delete this because it's always a good idea to write code from scratch anyways
because then you understand what you're doing and it's good practice for you guys to undertake.
So at this point we're going to start writing our code and we're going to start off by including a standard
header file, and these concepts will explain in even more detail.
But this pound symbol is basically a preprocessor define that says we want to include some other code
somewhere built from C plus from the C standard library.
We can also include our own header files later, but right now we just say include standard IO.H You
see the syntax highlighting happening and we just say include and then the next line of code we want
to write is we want to write our main function.
Our main function is our entry point to the program.
This is the function that gets executed when we run our program, run our executable.
Now, the main function has a lot of different variations.
We're just going to create it with INT data type and again, it's highlighted in purple and then we
just say main and then we can just have empty parentheses.
And then you'll notice when you type in a parentheses that it's red because there's no ending, right?
Parentheses.
So left parentheses starts a function prototype function definition, and then a right parentheses will
end it.
Well, this function doesn't take any parameters, so we're just going to keep it empty.
Now, incidentally, C also allows you to put void in there, which is a special keyword, but we're
just going to make an empty for now and then we're going to actually create our function and all functions
start with the left curly brace.
So we're going to have a left curly brace.
And again, that's red because in order to end the function, we have to have a right curly brace and
a left curly brace begins the function block.
Basically, anything in between the left function and left, curly brace and the right curly brace is
code inside of a function.
And again, these terms may not be completely understandable function, things like that.
We're just writing our first program that will demonstrate some understanding of the syntax and then
you'll have a challenge and so forth.
So whenever you have a red curly brace, you have to have an ending curly brace.
Now, incidentally, the IDE will add it for you when you hit the return after adding that left one.
And so what I'd like to do now is I'd like to write some code that will basically ask the user to enter
in their favorite number, and then I'll just print out their favorite number.
And again, some of this information will be detailed as far as syntax in later videos, but we want
to get our first program written and we want to be able to compile it.
And so at this point, we're just going to basically create a variable that stores information and it's
going to store our favorite number.
So we want to have it of type INT and we're just going to name it my favorite number and we're going
to initialize it to zero.
We're going to assign some data to it, right?
And we'll talk about data types and variables and again, more of these concepts in future videos.
We always want to use good naming conventions for variables that are stored our data, and then we're
just going to ask the user to enter some information.
So we're going to use a function called scanf for this.
And again, inside double quotes, we're going to just put our data type specifier percent D and a backslash
or an ending quote.
And then we're going to store that data inside of a variable called my favorite number.
And so you should be typing along with me to just see how we can write code and get input from the user
and so forth.
There will be again another video that specifically explains how to get input.
So we're going to also ask the user to enter a number.
So we want to display some output to the screen.
So we're going to do something like please enter your favorite number, right?
And then add a line feed for.
And you'll notice everything is enclosed in double quotes.
And then we do a semicolon to end that statement.
And you also notice that other statements in C such as the include directive don't have a semicolon.
Functions don't have a semicolon.
So then we have to use an enter number and then we're going to just print out and tell them what their
number is.
So we're going to say print out, you entered number and we're going to use a format specifier again
explained later backslash n for line feed.
And then we're going to display the value of the variable, which is my favorite number.
And then we're going to end our parentheses and our semi at our semicolon.
The main understanding of this code here is that we have a lot of code completion for us with with parentheses,
ending parentheses and so forth, and also ending quotes, double quotes.
So the IDE does a lot of nice things for you.
And then we have the syntax highlighting again, this is kind of just for getting you familiar with
some of the syntax for C and then because we have an int, we just want to basically say return zero,
meaning we don't have any errors and so then we can save our code, we can hit control.
S And what you can actually do is since our first program is in bold, that means we can actually compile
this and we can right click and we can actually say compile and then you'll see output in the build
window.
That's whether or not it was successfully compiling with no errors.
Okay.
And so we just wrote our first program that did something very simple asking the user for their favorite
number, getting that input and then displaying the output.
And again, a lot of these concepts, getting input, displaying output format, specifiers, functions,
those are all going to be later defined.
The purpose of this video is to just write some code and be a little bit familiar with some of the syntax
and be able to compile that code.
And so we didn't have any errors.
So in the next lecture, we're going to I'm going to actually show you how you can build, right?
We already talked about C programs and how there's many steps to create a binary and executable program,
right?
One is compiling, one is linking up to this point we've only compiled now we have to actually build
our entire project so that it links and creates our program executable.
So we'll see in the next lecture.
Thank you.