In the first part of this series tutorial we had come to know about computer programming, how to design a program, how to implement an algorithm etc. Today we will know about C language, various types of programming language, C compilers and finally how to write a hello world program in C language.
C Language
The programming language C was originally developed by Dennis Ritchie of Bell Laboratories and was designed to run on a PDP-11 with a UNIX operating system. Although it was originally intended to run under UNIX, there has been a great interest in running it under the MS-DOS operating system on the IBM PC and compatibles. It is an excellent language for this environment because of the simplicity of expression, the compactness of the code, and the wide range of applicability. Also, due to the simplicity and ease of writing a C compiler, it is usually the first high level language available on any new computer, including microcomputers, minicomputers, and mainframes.
- Ada
- Modula-2
- Pascal
- COBOL
- FORTRAN
- BASIC
- C++
- C
- FORTH
- Macro-assembler
- Assembler
- Creating the program
- Compiling the program
- Linking the program with whatever functions are needed from the library
Popular C Compilers
In this tutorial we are going to use the Microsoft Visual Studio 10 IDE and its integrated compiler.- Create a new project by clicking File->New->Project.
- From Installed Template choose other language
- Choose language Visual C++
- In Visual C++ choose tab Win32
- Choose project type Win32 Console Application
From the dialog box click on Next button.
In the W32 Application Wizard please ensure the application type is console application and in the additional options uncheck the precompiled header then click finish.
The Hello World C Program
To start programming, right click on Source Files and add a new item. You need to make sure below two points,
- Select C++ File to add
- Name the file with extension to .c, default is .cpp. To work with C language program source file name should be with extension .c In this case I am giving source file name as hello_world.c
So now we are set to write our first C program. The basic structure of a C program should be
#include header files The main function(){ Code in the main function }
Each C program must follow this structure. There are lots of header files come with the c compilers. We can use this header files in our program by just the include() preprocessor. Just like
#include<stdio.h> #include<conio.h>
Here we included stdio.h file to use its build in functions like printf(), scanf() etc. This is the most used header file we generally use in a c program. The purpose of using conio.h will be described in time.
So the main block will be
void main(){ printf(“Hello!. This is our first c program.”); getch(); }
The main() function is the starting point in a C program and there must be one main function in a c program. C compilers execute a c program from top to bottom starting from the first instruction in the main function. Each function must have a return type in c language, here void is the return type of the main function that returns nothing. The printf() function shows generally the message it argument-ed. So our program should show the message "Hello! This is our first c program" . The getch() is a build in function from header file conio.h that waits until a key is pressed when the output is showing in the console. To compile and execute the program press F5 and we will see(if everything is okay that means there is no error in our program)