The goal of this blog is to break apart some of what we wrote in the last blog and to understand some more concepts.
How Does a C Program Work?
First of all, the way a C program works is by writing out what we want the computer to do in very specific terms. Imagine that the computer is super dumb and you have to write down every single instruction.
Imagine you are a computer and I told you to share this blog. It seems simple enough, right? WRONG! If you were a computer, I would have to really spell it out. I mean reaallllyyy spell it out! Because of this, to tell you to share this blog, the instructions might look something like
The idea of explaining everything in detail is called an algorithm. This is an algorithm to share my blog post. I want to modify the algorithm a bit so that it can be used to share any blog on my website:
Computers are Dumb
Computers don’t have a memory quite like we do…. I mean they are really dumb. As a result, to tell you to share another blog, I have to repeat all of the instructions.
There are 12 commands now! 6 for the first video, 6 for the second. What if we could just take all of these commands and extract them as one command? Well, we actually can! This is known as a function. Let’s create a function called shareBlog().
Now, each time I want you to share a blog, I can just say shareBlog(). This is called calling or executing the function.
What are the () for? That is where I tell you what blog I want you to share. shareBlog(“C Programming Tutorial 10”), for example. This thing I’m passing in is known as an argument.
What if I added to the function steps for you to look at how many people have shared the blog and ask you to tell me? When I give you a request, you then return a number to me. This is known as a function return.
Finally, why am I telling you all of this? Because in C, we start every program with a function called main. For this reason, when our program is run, the main function is executed.
In the next video we will be discussing more specifics about the code we wrote in the hello world program.
Do you enjoy these blogs? Check out the next one!