Read + Write + Report
Home | Start a blog | About Orble | FAQ | Blogs | Writers | Paid | My Orble | Login
 
Weird and wonderful facts and trivia, useless information, gadgets, idiots, criminals, and heaps of humour - you name it, we've got it!

FIREFOX USERS TAKE NOTE: You may be missing half of the page for some strange reason, so you may want to try another browser to view the site accurately.

Choose categories or enter a term into the search box on the LEFT hand side of the page for other related posts.
Custom Search

C tute 1: hello world

July 27th 2006 03:31
Today I am going to do a brief introduction to the C programming language. To complete this lesson you will need a compiler. I will be using bloodshed dev (http://www.download.com/Bloodshed-Dev-C-/3000-2069_4-10019857.html) and the tutorials will assume you are too. This is going to teach you how to write a simple hello world program.

Getting started

Open your compiler and from the file menu select new->source code. Once you have done so type the following code.

#include <stdio.h>
int main()
{
printf("Hello world\n");
getchar();
return 0;
}

Then go to file->save and save it as a c source file names "Hello world". Now, go to execute->compile, and then, once this is complete, execute->run.

This should open up a window which display the words "hello world", and then waits until you press enter. When you do so it should close.

Looking at the code

So what do all the individual pieces mean?

#include <stdio.h>

This tells the compiler that it needs to include all the code that is contained in the header file stdio as well as all the code that you write. This is what gives you access to many of the functions that you use.

int main()

This tells the compiler that the function main, will return an integer.

{

This signals the beginning of a function.

printf("Hello world\n");

This function outputs "hello world" to the screen. "\n" inserts a line break at the end of this and the ";" marks the end of the function.

getchar();

This function tells the program to wait for input from the keyboard. It ensures that the program doesn't open, display "hello world" and close, all before you have a chance to see any of it.

return 0;

This tells the compiler what value to return to the computer. We will return to this later.

}

This marks the end of the function

Well that's it for today. With the next post I will deal with inputting text.

Adam

121
Vote


   
subscribe to this blog 


   

   


Add A Comment

To create a fully formatted comment please click here.


CLICK HERE TO LOGIN | CLICK HERE TO REGISTER

Name or Orble Tag
Home Page (optional)
Comments
Bold Italic Underline Strikethrough Separator Left Center Right Separator Quote Insert Link Insert Email
Notify me of replies
Your Email Address
(optional)
(required for reply notification)
Submit
More Posts
1 Posts
4 Posts
2 Posts
683 Posts dating from April 2006
Email Subscription
Receive e-mail notifications of new posts on this blog:
0
Moderated by MelissaA
Copyright © 2012 On Topic Media PTY LTD. All Rights Reserved. Design by Vimu.com.
On Topic Media ZPages: Sydney |  Melbourne |  Brisbane |  London |  Birmingham |  Leeds     [ Advertise ] [ Contact Us ] [ Privacy Policy ]