C First Program

In the previous lesson, we learned how to set up the environment for C. Now, we will see how to run C first program.  It’s quite easy. Let’s begin with launching Turbo C and running C first program.

Go to Start > Turbo C

Open Turbo C and open a new project,

File > New

Open-new-C-project

Firstly, save it and give any name with extension c. Here, we have given the name Study1.c,

First C program file saved in Turbo C

Now, let’s add a demo program

Let’s work on our first C program,

Here,

#include

It is the preprocessor and the first word read by the compiler

stdio.h

It is the header file.

int main()

main() function with return type int.

printf
Used to print the formatted string to stdout. The standard output is stdout.

return

Terminates the function execution and the return statement returns the control to the calling function.

When you will run the above program, you won’t get an output in Turbo C, but the program runs correctly. To allow the output to be visible on the screen, remove the return statement and add the return type to the main() function as shown below, with getch() method.

Also, add <conio.h> header file and getch() for output to be visible in Turbo C++. The MS-DOS compiler uses the <conio.h> header file to show console input/output.

getch()  is used to read a character from the screen and is added just before the program ends. It is a predefined function in <conio.h> header file. To clear the screen, you can also add clrscr(); just after the declaration.

We’re using the <conio.h> header file and getch() to show output on Turbo C, which is our MS-DOS compiler.

Here’s or final C program,

Here’s our C program on Turbo C compiler,

C First Program

For output, press Ctrl+F9.

The following output is visible,

First C Program output

In this lesson, we learned how to run our first C program in Turbo C. Similarly, create a new file in Turbo C, write C code in it and run it as shown above.

If you liked the tutorial, spread the word and share the link and our website Studyopedia with others:


For Videos, Join Our YouTube Channel: Join Now


Read More:

Setup Environment for C (Download and Install Turbo C/C++)
C Programming Examples
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading