How to Compile a C program using Turbo C++?

In the previous article, you learned how to install a Turbo C++ compiler on a windows system. After installation you must write your first C program ,and compile it. In this article you will learn to compile your first C program.

Advertisements

Prerequisite to this article is installing turbo C++ compiler on your windows computer.

Writing Your First Program

To start writing your first C program using Turbo C++ compiler follow the steps given below.

Open Turbo C++ Initial Screen

The first step is to open the Turbo C++ initial screen which is shown below. You can do this after installation either by clicking the desktop icon or click the Turbo C++ icon in start menu. The screen look like the following.

Figure 1 – Turbo C++ Initial Screen

Start the Turbo C++ Compiler

The next step is to start the Turbo C++ compiler by clicking the “Start Turbo C++” compiler. You will see the compiler window shown below.

Figure 2 – Compiler Screen- 2

Before you write your program, make sure that the directories are correctly configured for the compiler. Go to Options > Click Directories in the Menu Bar. The following screen will appear, so you must verify the directories given here.

Figure 3 -Compiler Screen-Include directories

The directories must exist with all the required files and path to directories must be correct. You must verify this manually. If necessary, change the directories to where the Turbo C++ files exists.

Advertisements

Create a New Source File (prog.C)

By default, the program name is noname.cpp, but we want C source file. Go to File menu > Click Save as and in the Save File As box, type the name of the C source file.

Prog.C

Now, you can start writing your C program code. For this example, we will write the ‘Hello World’ program.

#include <stdio.h>
int main()
{
       printf("Hello World!");
       getch();   
       return 0;
}
Figure 4 – Compiler Screen – Write source code

Compile the Program

There is two ways to compile a program in Turbo C++.

  1. Press Alt-F9 (as instructed in the status bar of Turbo C++)
  2. Go to Compile tab of Menu bar and press Compile or Build All.

The compiler will finish compilation with no error or with some warnings. If an error is encountered, then the compilation is aborted and the problem line or lines are highlighted with error description.

Figure 5 – Compile the program

In the above program, we purposly omitted semi-colon (;) at the end of the C statement. This resulted in an error. The program indicate the line no, then name of the program and the error description.

Execute the Program

The program is created, you can run and test the output. To run the program, go to Run menu and click Run or press Ctrl + F9.The output of the error-free compiled program is given below.

Figure 6 – Output-from the program

References

  • Balagurusamy, E. 2000. Programming in ANSI C. Tata McGraw-Hill Education,.
  • Brian W. Kernighan, Dennis M. Ritchie. 1988. C Programming Language, 2nd Edition. Prentice Hall
  • Kanetkar, Yashavant. 20 November 2002. Let us C. Bpb Publications
Advertisements

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Exit mobile version