How to Create A Hello World Program in C
- after you already install the code blocks and also the compiler ( you can see the tutorial to install code blocks here http://howtobegininc.blogspot.co.id/2015/10/how-to-install-compiler-in-cc.html ). now you need to make a program. how to start a program? let me guide you how to make a "hello world" program in C.
- first of all, you need to begin the program with #include <stdio.h>. it will help you to read the source code. to continue, i will give an example also the explanation :
#include <stdio.h>
int main ()
{
printf("hello world \n);
return 0;
}
- the main explanation :
- #include <stdio.h> - this line of code called as "Standard Input/Output Header File". you need this to begin your program. this will let us to use a certain commands for input or output in our program.
- int main () - this int is called the return value or data types (integer, float, double, char, etc). every program must have main ().
- {} - these curly bracket (one at the begning and one at the end) are used to make all of your command in one group together. these curly bracket also used to mark the begining and ending of a program.
- Return 0; - this is mean that you must return an integer int main (), when we wrote "int main()"
- // - this mean anything you write in 1 line after // will be as a comment.
- printf ("hello world \n"); - this is used to print a program, or the output. if you want to print a program, you must ended with ";". printf is used to print a program. after printf you must make a bracket (), it used to print the data inside the round bracket. also you need "". this is used to read what do you want to print. the hello world inside the "" also called as a string. this is what do you want to print. \n is called as "escape sequence"
- \n = to make new line
- \t = tab
- \f = newpage
- \v = vertical tab
- if you already knew and already made the following code, you can compile it by click build, compile current file ( ctrl + shift + F9).
- if the compilation was succes, you need to save your file. give this name to your file as a beginning "helloworld.c".
- if you have some error with the compilation. that must be something wrong or you didn't follow the instruction correctly. or the compiler was not detected, you can fix it by following this site http://howtobegininc.blogspot.co.id/2015/10/how-to-install-compiler-in-cc.html
- after the compilation success, please build and run it by pressing F9
- if it is succes. you will got this :
Tidak ada komentar:
Posting Komentar