There is no one in this world who is born as a programmer 😉 To write efficient programs using any languages you have to learn it by doing! You have to write as many different programs using as many different algorithms. You have to break codes, make errors, debug errors and sometimes you have to approach the same problem using 2 or 3 different logics. To learn “C language” efficiently, you must write a lot of different C programs using the concepts of C language. To do this you need a good compiler for C language setup on your computer. Turbo C is one such compiler for windows operating system. If you are running a Linux operating system, you can use the GCC compiler. A compiler does the job of converting codes written in C language to machine language, so that it can be executed.

First of all you need to install and setup Turbo C compiler on your computer. If you are using Windows XP – you can download  Turbo C and install it directly. On the other hand if you are using Windows Vista or Windows 7 – you may read the following article to setup Turbo C on your computer.

How to install Turbo C/C++ on Windows 7/Vista

Okay. I assume that you have installed Turbo C on your computer perfectly. Now lets see how to use Turbo C to RUN your C programs.

Open Turbo C from your Desktop or Programs menu. Select “File” from Menu bar and select option “New”

If there are any default lines of code present inside editor please remove all of them. The text editor should be blank. Now you may type in the following program in your Turbo C editor. This is a program to print “Hello World” on the first line of your output screen and to print “Thank You” on the next line of your output screen.

Note:- You don’t need to type any lines that comes after // in your Turbo C editor. Any text that is placed after // are comments and are written here with C code for your ease of understanding.

#include//Preprocessing standard input output header file

##include

void main() // Main function which is the entry point to any C program

{

printf(“Hello World\n”); // Function to print any data on output screen

printf(“Thank You”);

getch(); // Function get an input data from keyboard


}

If you are really new to C programming you may not understand this simple lines of code perfectly. Don’t worry about that, we will learn those in coming chapters.   First of all keep in mind that C is a procedural programming language – which means these codes are executed line by line; beginning from the first line #include. The first two lines that begins with #include are 2 preprocessors (which we will explain later). The line void main() is where the real codes of program begin. You may note 2 parentheses { } that follows void main(). The whole program must be kept within these 2 parentheses. So your C programs skeleton would be like

Preprocessors

void main()

{

Lines of code/Program

}

printf() is a standard command/library function in C language which performs the task of printing some data on the output screen. What ever data we pass through the enclosed parentheses () of printf function will get printed on the output screen and the data can be integers,characters or strings. So the line printf(“Hello World\n”); will print Hello World on the output screen. You may note the \n that follows Hello World. That \n is the command for new line. The printf function will move the cursor of output screen to next line upon reading the \n sequence inside the parentheses. Now in next line printf(“Thank You”); will print the words Thank You

Note:- Almost all the lines of code inside the void main () { lines of code } must end with a semicolon. There are exceptions in some cases like usage of loops (for, do while) etc which we will learn later.

The last line of code getch() is actually a standard input library function in C language. getch() -known as get character- is a function get an input from the keyboard. Upon executing the getch() function the program control will wait until a character is inputted by the user from keyboard. Here in this program this getch() function is used as a trick to hold the output screen live for a desired period of time by the user. The output screen will get closed only if the user makes a key press.

Note:- You may try executing this program without getch() function. Observe yourself what happens!

I hope that’s enough for a basic explanation of the program. If you still have doubts please ask through comments. Now lets RUN this program using Turbo C. Before going into the steps, you may SAVE your C program. Select “File” from menu -> click-> Save. Name the files as ->hello.c or some other name with a .c extension. See the screen shot below.

Turbo C tutorial

How to Compile a C program in Turbo C ?

The first step is compiling. Compiling makes sure your program is free of syntax errors. How ever compiler won’t check for any logical/algorithmic errors. There is a lot of process that happens while the compiler compiles a program – which we will discuss later in coming articles. To do compiling – Select -> Compile from menu and click-> compile. See the image below.

Compiling a C program in Turbo C

After compiling, you will see a dialog box as shown below.If the compilation is success – you will see a “success” message. Else you will see the number of errors. Both are shown using screen shots.

The screen shot of a “success” compilation

Compiling a C program in Turbo C

The screen shot of an “Error” compilation.

How to compile a C program

Here the 2 errors are because I removed semicolons from the 2 lines

printf(“Hello World\n”)

printf(“Thank You”)

You may run the program only after a “Successful” compilation. Make your program free of errors before you RUN the program.

How to RUN a C Program in Turbo C compiler?

To RUN the program – you may select ->Run from menu and click -> Run (as shown in the image below).

How to RUN a C program in Turbo C

Now you will see the output screen as shown in the screen shot below.

Output of a C program

To close the output screen press any key (please remember/refer the part I mentioned about getch() function in this article).

Author

20 Comments

  1. i can say that its wrong we can use only int main()n not void main to dont share wrong thing with others bczzzz return 0; returns int value … if u want more information go and search in ANSI standard website..

  2. Can you help me with my assignment, we have to write a program that have this output:

    Enter 1st Quiz Score: 12
    Enter 2nd Quiz Score: 19
    Enter 3rd Quiz Score: 9

    The sum is 40.
    The average is 13.

    I appreciate you help. Thanks!

  3. Rameesha

    turbo C++is not getting started?? whats the issue?

  4. it shows error as
    unable to open include file ‘STDIO.H’

  5. m trying to compile n run my program but there is some problem..my program is free of errors but ctrl+f9 and alt+f9 s not working..is it any setting prblm??? reply fast plzzz 🙂

  6. I HAVE USED ‘*’ SIGN TO DRAW MY INITIALS FOLLOWING THE STEPS SHOWN BY U,
    BUT “K” IS LOOPING ,HOW CAN I STOP IT

  7. Please mail me how to write a programme what does #include ,void main(),float ,printf(),n all mean n how to write a programme of arthematic sum n all plz

  8. shashikanth

    thank you, upload this type of simple program it is useful for learner i want to know about turbo c++ i am requesting add more program for the learner thank so much

  9. thanks a ton. the link provided to download turbo c/c++ simulator was way helpful than any other sites link. it was a big help 🙂

  10. ADITYA R K

    Sir,I am extc student and i want to ask that what is coding for precedence of operators and how to add extra line in between of programs.

  11. Sir, if i print first 500 prime nums … screen is howing only last ten numers,, how to see / roll back to previous numbers ? please reply,,,,

  12. i have turbo c installed at local disc c, when i finished my program there are no errors but when i input a number it shows nothing, i mean there is no output, but i put printf on the code. what is the problem? when im at school it is showing output. help me

  13. How can I use ‘Save as’ in turbo c to save my programming in another drive in my computer???????/

    • jojo

      You need to change the directories path in Turbo C. Better not to do that! To get a copy of the file, you may just COPY the .C file from your TC folder and PASTE it wherever you want.

    • when we compile program why displed compiled more then in the programe line.