Introduction To C

Submitted by M E Senturk on Wed, 05/06/2009 - 01:48

Hello everybody,

This is the very first article of this section. There will be an
example code for "hello world" program and we will see the main
structure of c programming.

Here goes the code

 

#include <stdio.h>

int main()
{
    printf("Hello World!");
    return 0;
}

 

As we see, first line of the code is

#include <stdio.h>

This is the where we added standart input-output library.In "C", you need to include libraries

in order to use functions. We used printf function to write "Hello World" in command window.

(By
the way command window is cmd for MS users and terminal for Unix
users.) Standart input-output library has this function and some other
functions that you will need. If you wonder these functions you may
look at
http://www.cplusplus.com/reference/clibrary/cstdio/ to see these functions and what are they for.

 

Third line(i assume you counted the blank line after include) starts with

int main()

well, actually this is a function call. We will discuss about
functions in the future. main is the function that runs first when we
start the program. You can call other functions in this main function.
There is a three letter word before "main()". This means, type of the
function is int(integer). If you don't want to mess with types, then
you should use "void". We also talk about the function types in the
future.

 

You should write function's duty in curly brackets. In here, we have
written "printf" function between curly brackets. And there is one
other thing between these brackets.

return 0;

This is the thing that you don't need to know until you learned
about the functions and how to write a function. Until that, you always
write it in that way before you close the curly bracket if you have
written int before main as we did now.

 

Take care, keep practising.

 

 

PS:It was not a good article, i know, actually this is the first
time i have written an article in English. I hope it will get better
soon.