Compiling a C program

QBASIC is interpreted language so no need to compile, it can be run directly. However, C has compiled language so it must be compiled before running it. The process of converting source code into object code is called compiling. By the compilation process, the C source code file will be converted into an executable file. You can only run the executable file to get the output (result) of the program. While compiling it checks the typing or syntax errors in the program but it cannot find out the logical errors. There are many C compiler software. Here we are using the Turbo C++ compiler.
There are two ways of compiling:
  1. Using IDE (Integrated Development Environment)
  2. Using Command-Line Compiler

Using IDE (Integrated Development Environment)

Some compiler software provides a complete programming environment for writing, managing, compiling, debugging, and testing C source code. This is known as Integrated Development Environment (IDE). The IDE has its own text editor feature so you can directly type your program code in the IDE then you can compile it, debug it and run it.
Let’s suppose the program is typed in any text editor such as Notepad and is saved with named hello.c, Follow the following steps to compile this source code file in Turbo C++ IDE environment:

Step 1:

Load the Turbo C++ compiler by double-clicking on the TC.exe file from its folder. Then you can see the Turbo C++ IDE environment as shown below:
Easy Steps for Compiling a C Program || NEB Class 12

Step 2:

Go to the File menu and then click on the Open option. Then Open file dialog box appears.

Step 3:

Go to the required location then select the source code file “hello.c” and then click on the Open button or press enter key. Then the program code of that file appears in the IDE.
Easy Steps for Compiling a C Program || NEB Class 12

Step 4:

To compile the program, click on the Compile option from the Compile menu or press the shortcut keys Alt+F9 from the keyboard.
If the program has any syntax errors, the compiler gives the error message. Press any key then the error detail window will appear. Correct the existing errors and then compile again.
Easy Steps for Compiling a C Program || NEB Class 12
After compiling you can see an executable file named hello.exe is now created alongside the C source code file.
After compiling you can run the C program in the following ways:

Step 5:

Go to the Run menu and click on the Run option. Or press the Ctrl+F9 keys from the keyboard.
Or, you can directly run the compiled program by double-clicking the .exe executable file created by the compiler alongside the C source code file.
You can see the output of that program by pressing the Alt+F5 keys. If you use the getchar() or getch() command in the program, no need to press the Alt+F5 keys to see the output, see the following example for detail.

Let’s type the following C code directly in the IDE then compile and run it.


#include <stdio.h>
int main(void)
int a=50, b=25, c;
printf(“n sum of two numbers is %d”,c);
return 0;
When you Run (Ctrl+F9) this program you will get output as follows:
sum of two numbers is 75


In this example, a new command getchar() is included. This is another function call that reads in a single character and waits for the user to hit enter before reading the character. This command is included because many compiler environments will open a new console window, run the program and then close the window before you can see the output. This command keeps that window from closing because the program waits for you to hit enter. The getchar() function is included in header file

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *