C Programming Tutorial 5 - How a C Program Works - Part 2

submitted by mkenny400 on 03/19/18 1

This video will be dissecting the hello world program that we wrote in an earlier video. The first thing we will look at is the main function. It is important to realize that the definition of every function looks similar to this. We have the return data type, the name or identifier, parenthesis for any arguments, and then a code block designated by curly braces. Within the code block, we have what are known as statements. This is when we are telling the computer to do something. We always, always, always use semicolons. It will be clearer soon when you are supposed to use a semicolon and when you are not. What you need to do is look at this program and try to memorize all of the syntax here. If you can write this all without looking at anything, you're doing very good.   Everything inside of the curly braces belongs to the main function. You can see that this function does not require that we pass anything into it. At the end of the function we have return 0. This is how we say that the program worked. 0 = good. We can use this to denote whether the program worked or not. For example, we could use a -1 to say “bro something went wrong.” 0 is an int, which is short for integer. That is why the word int comes before the name of the function.   Inside of the function we are calling another function called printf(). This shows that functions can call functions. This function is used to output something on the screen. The thing inside of quotes is the argument. We give this function some data and it will spew it on the screen. Now, this \n is known as the newline character. This will make the program go down to the new line.   Now I have a question for you…How does the C compiler know what this printf() is? We haven't defined it anywhere! Well, that brings up the concept of includes. C actually has a bunch of functions that are already available to us and we can include certain files to gain access to new functions. This means that the printf function comes from stdio.h.   Now, in the next video, I'm going to go over some of the most important Linux commands so we actually know how to do things in the command line. It's going to be awesome and educational, so catch you there! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×