Recent

How To Write, Compile and Run A Program - C Language Tutorials Part 2

How To Write, Compile, and Run Your First Program In C Language - Step By Step Guide
This tutorial will help you how to write you first program in C language and compilation of the program and how to run the C Language compiled code.

Step 1: Open Turbo C IDE
First of all open Turbo C or  Dev-C++ Integrated Development Environment (IDE), an blue screen will appear in front of you (blue screen will open if you are using Borland's Turbo C IDE), this is the screen where you can write your program for C language.

Open Turbo C to write a program


Step 2: Write A Code
Write the code written below in the blue screen of your IDE.

#include <stdio.h>
#include <conio.h>
void main(void)
{
printf("Hello World");
getch();
}

here #include is use to define the header files and libraries in a program, like default functions which are defined in compiler we don't need to define again in a program, like a "printf" function is predefined function so we don't need to define it again, we just use it, we are using here two header files with extension .h, one is stdio.h and another is conio.h both uses for input output functions like printf() and getch().
void main(void) is the main function from where the compiler starts the execution of program.
printf() is the function in C which is use to print string written in it on screen as in our program hello world is printed in our console when we run the program.
getch() is the function which is use as the input, it get the first key you press when compiler executing it. any key you will press it will store it.
{ } these are the boundaries of your function.


Step 3 : Compile A Program
To Compile a C language code using Turbo C, click on "compile tab" in menu bar or press alt and then C, then select Compile. it will compile your code and generate the compiled object code for your code, we have to compile our code because C is the high level language and computer cannot understand high level language it only understand the binary (0/1) language, therefore we have to compile(translate) our code.
you can press (Alt+F9) shortcut key to compile your code directly as shown in figure


Step 4: Execute The Code
After Compiling your code you are now ready to run the code which will actually generate a .exe file of your code and run it, but your code will only run if and only if it is written correct and don't have any syntax error.
press Alt then R to go to Run menu or click on "Run tab" in menu bar with mouse to open Run option then click on Run to Execute you Code you can also use shortcut key (Ctrl + F9) to direct run your code.
Note: if you don't compile your code before running, Turbo C will automatically first compile your code and then runs it.

Output Screen
It's Done, here is your output screen with written Hello World on Black Screen.



No comments