Visitors

Pages

Jumat, 16 Desember 2011

Tutorial C Language : Create a Simple Program

This is my first post about C programming, in this post i will try to explain Tutorial C Language : Create a Simple Program. Check it out :

1. You must have the software first, if you not please the read article below :

PROGRAMMING C / C++ - FREE SOFTWARE DOWNLOAD

Then install it.

2. Open the software then make a new file (CTRL+SHIFT+N)
Let's GO !

Probably the best way to start learning a programming language is by writing a program. Therefore, here is our
first program :

// my first program in C
#include <stdio.h>
main ()
{

printf ("This is my first program");

system ("pause");

}

Now, i will try to explain the program per line.

// my first program in C
This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is.

#include <stdio.h>
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines. with expressions but indications for the compiler's preprocessor. In this case the directive #include tells the preprocessor to include the iostream standard file. This specific file (stdio.h)includes the declarations of the basic standard input-output library in C, and it is included because its functionality is going to be used later in the program.



main ()
This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C program. For that same reason, it is essential that all C programs have a main function.

{
To declare the beginning of the body function and also start the execution of the program.

printf ("This is my first program");
This line is a C statement. A statement is a simple or compound expression that can actually produce some effect. printf represents the standard output stream in C, and the meaning of the entire statement is to insert a sequence of characters (in this case the This is my first program sequence of characters) into the standard output stream (which usually is the screen).

Notice that the statement ends with a semicolon character (;). This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement.

system ("pause");
make the system stop, so the program not closing directly.

}
To declare the beginning of the body function and also close the execution of the program.

After you finish writing the program, click Build >> Build and Run (F9).
And this is your first program.

0 Comments:

Posting Komentar

Get Money From Here