The first program that anybody learning a new programming language is called Hello World, which simply prints that to a console window. It's also useful to check that your set-up is working correctly.

Transcript

The first program that most people create when they're learning a new programming language is what's called Hello World, and this simply prints the string Hello World to the screen and then exits. This is also a good test around to see if your environment is working if you're working on a new computer, for instance, it's that simple so let's get started.
So, I've opened our atom editor, and this is what you might see if you haven't used it before. All we need to do is just close all the welcome tabs and we can get started. So, we'll go to File, New File and we'll have this blank document. The first thing we should do though is saving it somewhere so, File save, or you can use Ctrl S, I like to keep my programs organized so what I'm going to do is create a folder for them and inside that, I'll create one for each project. So, for instance, this one is going to be the Hello World and the File name for this going to be Hello World.C and the .C is important otherwise it won't be recognized as a C File by the Atom editor. Really good habit to get into, is to write little notes throughout your program, this way if you need to come back to it a couple of years later, you know exactly what it's going to do and you won't have to waste time trying to work out what you've written, so I'll start off with one of those notes and I'm just going to write what this program does.
So, what I've written is my first program prints Hello World to the command prompt and then exits because that's all it does. Next, we need to enable the program to be able to print out to the screen and the easy way to do this is to use the libraries that are already written for you. So, we'll tell it to include them and in this case, the library that we need is called stdio.h, which stands for "standard input/output" now every program needs a start point and for C it's called the main function. So, the way to write that is in main some brackets and then void and then underneath that we'll put some curly brackets or braces, and this is going to be where our program is contained. So, to print to the screen we'll use what's called printf so I'll tell it to print Hello World and we'll add a new line character at the end. Now, because we've used printf I'm going to write another little note at the top to say where we got it from and I'll also add a little reminder note for what printf does. The last step is to tell our program to exit and the way to do this is to tell it to return zero.
And that's it we're done so to run our program and press F5 and you'll see it pops up with Hello World now if this was a bit confusing, don't worry, in the next lesson I'll be going through this program very thoroughly explaining every little bit too.                                                                

Comments


Loading...
Feedback

Please continue if you would like to leave feedback for any of these topics:

  • Website features/issues
  • Content errors/improvements
  • Missing products/categories
  • Product assignments to categories
  • Search results relevance

For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

Makers love reviews as much as you do, please follow this link to review the products you have purchased.