What Is C Language ?

C language is a powerful and compact computer language that allows you to write programs that specify
exactly what you want your computer to do. You’re in charge: you create a program, which is just a
set of instructions, and your computer will follow them.

Programming in C language isn’t difficult, as you’re about to find out. I’m going to teach you all the fundamentals of C programming in an enjoyable and easy-to-understand way, and by the end of this tutorial you will be able to write your first program in C language.

Why to use C?

C was initially used for system development work, in particular the programs that make up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as code written in assembly language. Some examples of the use of C might be:

  • Operating Systems
  • Language Compilers
  • Assemblers
  • Text Editors
  • Print Spoolers
  • Network Drivers
  • Modern Programs
  • Databases
  • Language Interpreters
  • Utilities

C Language Program

A C language program can vary from 3 lines to millions of lines and it should be written into one or more text files with extension “.c”; for example, hello.c. You can use “vi”, “vim” or any other text editor to write your C language program into a file.

Creating C language Programs

There are four stages, or processes, in the creation of any C language program:

• Editing
• Compiling
• Linking
• Executing

You’ll soon know all these processes like the back of your hand (you’ll be doing them so easily
and so often), but first let’s consider what each process is and how it contributes to the creation of a
C language program.


This is the process of creating and modifying C language source code—the name given to the program instructions
you write. Some C language compilers come with a specific editor that can provide a lot of assistance
in managing your programs. In fact, an editor often provides a complete environment for writing,
managing, developing, and testing your programs. This is sometimes called an integrated development
environment, or IDE.


The compiler converts your source code into machine language and detects and reports errors in the
compilation process. The input to this stage is the file you produce during your editing, which is
usually referred to as a source file.
The compiler can detect a wide range of errors that are due to invalid or unrecognized program
code, as well as structural errors where, for example, part of a program can never be executed. The
output from the compiler is known as object code and is stored in files called object files, which
usually have names with the extension .obj in the Microsoft Windows environment, or .o in the
Linux/UNIX environment.


The linker combines the various modules generated by the compiler from source code files, adds
required code modules from program libraries supplied as part of C, and welds everything into an
executable whole. The linker can also detect and report errors, for example, if part of your program
is missing or a nonexistent library component is referenced.


The execution stage is where you run your program, having completed all the previous processes
successfully. Unfortunately, this stage can also generate a wide variety of error conditions that can
include producing the wrong output or just sitting there and doing nothing, perhaps crashing your
computer for good measure. In all cases, it’s back to the editing process to check your source code.

Creating Your First C Program

Let’s step through the processes of creating a simple C language program, from entering the program itself to
executing it. Don’t worry if what you type doesn’t mean anything to you at this stage—I’ll explain
everything as we go along.

/* Your Very First C language Program – Displaying Hello World */
#include <stdio.h>
int main(vo{
printf(“Hello world!”);
return 0;

Hello world!

Run your editor, and type in the following program exactly as it’s written. Be careful to use the punctuation exactly
as you see here. The brackets used on the fourth and last lines are braces—the curly ones {}, not the square ones
[] or the round ones ()—it really does matter. Also, make sure you put the slashes the right way (/), as later you’ll
be using the backslash (\) as well. Don’t forget the semicolon (;).


Editing Your First Program

You could try altering the same program to display something else on the screen. For example, you
might want to try editing the program to read like this:

/* Editing of Your  first C Program */
int main(void)
printf(” try, try, try till you succeed !”);
return 0;

try, try, try till you succeed !

The \’ sequence in the middle of the text to be displayed is called an escape sequence. Here it’s
a special way of including a single quote in the text because single quotes are usually used to indicate
where a character constant begins and ends.


Dealing with Errors

Let’s step through what happens when your source code is incorrect by creating an error in your
program. Edit your second program example, removing the semicolon (;) at the end of the line with
printf() in it, as shown here:

int main(void)
printf(“If at first you don\’t succeed, try, try, try again!”)
return 0;

main.c: In function ‘main’:
main.c:5:1: error: expected ‘;’ before ‘return’
return 0;

When you compile this C program, you’ll see an error message that will vary slightly depending
on which compiler you’re using. A typical error message is as follows:

Here, the compiler is able to determine precisely what the error is, and where. There really should be
a semicolon at the end of that printf() line.

Let’s take input from user

# include <stdio.h>
int main()
int a ;
printf(“Enter an integer” ) ;
scanf(“%d” , &a );
printf(“Entered value is : %d\n” , a );
return 0;

Enter a integer21
Entered value is : 21


This isn’t actually part of the program code, in that it isn’t telling the computer to do anything.
It’s simply a comment, and it’s there to remind you, or someone else reading your code, what the
program does.

Anything between /* and */ is treated as a comment.
Let’s write a program with comments.

#include <stdio.h>        /* This is a preprocessor directive */
int main(void) /* This identifies the function main() */
printf(“Beware the Ides of March!”); /* This line displays a quotation */
return 0;}
/* This returns control to the operating system */

You can see that using comments can be a very useful way of explaining.


In C language, a keyword is a word with special significance, so you shouldn’t use keywords for any other
purposes in your program. For this reason, keywords are also referred to as reserved words.

auto else long switch
break enum register typedef
union return extern case
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _packed
Close Menu