You are on page 1of 10

Chap III: C programming language

Lesson 1 : Overview of C Language


C is a structured programming language developed by Dennis Ritchie in 1972 at Bell
Laboratories. It is one of the most popular computer languages today because of its structure,
high-level abstraction, machine independent feature etc. C language was developed to write
the UNIX operating system, hence it is strongly associated with UNIX, which is one of the
most popular network operating system in use today and heart of internet data superhighway.

1- History of C language

C language has evolved from three different structured language ALGOL, BCPL and B
Language. It uses many concepts from these languages while introduced many new concepts
such as datatypes, struct, pointer etc. In 1988, the language was formalised by American
National Standard Institute (ANSI). Between 1989 and 1990, a version of C language was
approved by the International Standard Organisation (ISO) and that version of C is also
referred to as C89.

Let's see the programming languages that were developed before C language.

Language Year Developed By

Algol 1960 International Group

BCPL 1967 Martin Richard

B 1970 Ken Thompson

Traditional C 1972 Dennis Ritchie

K&RC 1978 Kernighan & Dennis Ritchie

ANSI C 1989 ANSI Committee


ANSI/ISO C 1990 ISO Committee

C99 1999 Standardization Committee

The current latest version of C language is C11, which was introduced in 2011. It is supported
by all the standard C language compilers.

Many new features have been introduced in this version and an overall attempt to improve
compatibility of the C language with C++ language has been made.

The idea behind creating C language was to create an easy language which requires a
simple compiler and enables programmers to efficiently interact with the machine/system, just
like machine instructions.

C language compiler converts the readable C language program into machine instruction.

2- Why C Language is so popular?

C language is a very good language to introduce yourself to the programming world, as it is a


simple procedural language which is capable of doing wonders.

Programs written in C language takes very less time to execute and almost executes at the
speed of assembly language instructions.

Initially C language was mainly used for writing system level programs, like designing
operating systems, but there are other applications as well which can be very well designed
and developed using C language, like Text Editors, Compilers, Network Drivers etc.

3- FEATURES OF C PROGRAMMING LANGUAGE:


C language is one of the powerful language. Below are some of the features of C
language.
 Reliability
 Portability: this means that programs once written can be run on another machines
with little or no modification
 Flexibility
 Interactivity
 Modularity

 Efficiency and Effectiveness

4- USES OF C PROGRAMMING LANGUAGE:

The C programming language is used for developing system applications that forms a major
portion of
operating systems such as Windows, UNIX and Linux. Below are some examples of C being
used.
 Database systems
 Graphics packages
 Word processors
 Spreadsheets
 Operating system development
 Compilers and Assemblers
 Network drivers
 Interpreters
Note: C is called middle-level language because it actually binds the gap between a
machine level language and high-level languages.

5- C LANGUAGE IS A STRUCTURED LANGUAGE:

Structure oriented language:


 In this type of language, large programs are divided into small programs called functions
 Prime focus is on functions and procedures that operate on the data
 Data moves freely around the systems from one function to another
 Program structure follows “Top Down Approach”
 Examples: C, Pascal, ALGOL and Modula-2
Object oriented language:
 In this type of language, programs are divided into objects
 Prime focus is in the data that is being operated and not on the functions or procedures
 Data is hidden and cannot be accessed by external functions
 Program structure follows “Bottom UP Approach”
 Examples: C++, JAVA and C# (C sharp)
Non structure oriented language:
 There is no specific structure for programming this language. Examples: BASIC, COBOL,
FORTRAN
KEY POINTS TO REMEMBER IN C LANGUAGE:

1. The C language is a structure oriented programming language developed by Dennis


Ritchie
2. The C language is belonging to middle level programming language.
3. Operating system programs such as Windows, Unix, Linux are written in C language.
4. C89/C90 and C99 are two standardized editions of C language.
5. C has been written in assembly language.
Lesson 2 : C basic syntax
This C programming basics section explains a simple “Hello World” C program. Also, it
covers below basic

Topics as well, which are to be known by any C programmer before writing a C program.

1. C programming basic commands to write a C program

2. A simple C program with output and explanation

3. Steps to write C programs and get the output

4. Creation, Compilation and Execution of a C program

* How to install C compiler and IDE tool to run C programming codes

5. Basic structure of a C program

* Example C program to compare all the sections

* Description for each section of the C program

2.1- C PROGRAMMING BASICS COMMANDS:


Below are few commands and syntax used in C programming to write a simple C program.
Let’s see all the sections of a simple C program line by line.

C Basic commands Explanation

This is a preprocessor command that includes


standard input output header file(stdio.h) from the
#include <stdio.h>
C
library before compiling a C program

This is the main function from where execution of


int main() any
C program begins.

{ This indicates the beginning of the main function.

/*_some_comments_* whatever is given inside the command “/* */” in


/ any
C program, won’t be considered for compilation
and
execution.

printf(“Hello_World!
printf command prints the output onto the screen.
“);

This command waits for any character input from


getch();
keyboard.

This command terminates C program (main


return 0;
function) and returns 0.

} This indicates the end of the main function.

2.2- A SIMPLE C PROGRAM:

Below C program is a very simple and basic program in C programming language. This C
program displays
“Hello World!” in the output window. And, all syntax and commands in C programming are
case sensitive.
Also, each statement should be ended with semicolon (;) which is a statement terminator.

#include <stdio.h>
int main(){
/* Our first simple C basic program */
printf("Hello World I doing c programming! ");
getch();
return 0;
}

OUTPUT:
Hello World I doing c programming!

2.3- STEPS TO WRITE C PROGRAMS AND GET THE OUTPUT:


Below are the steps to be followed for any C program to create and get the output. This is
common to all C
program and there is no exception whether its a very small C program or very large C
program.
1. Create
2. Compile
3. Execute or Run
4. Get the Output

2.4- ENVIRONMENT SETUP:


Local Environment Setup
If you want to set up your environment for C programming language, you need the following
two software
tools available on your computer,
(a) Text Editor and
(b) The C Compiler.

Or you install an IDE(Integrated Development Environment) embedding both text editor and
compiler (codeblock, Turbo C, ….etc.
(a)Text Editor

This will be used to type your program. Examples of a few editors include Windows Notepad,
OS Edit command, Brief, Epsilon, EMACS, and vim or vi …..etc. The name and version of
text editors can vary on different operating systems. For example, Notepad will be used on
Windows, and vim or vi can be used on Windows as well as on Linux or UNIX. The files you
create with your editor are called the source files and they contain the program source codes.
The source files for C programs are typically named with the extension ".c".

Before starting your programming, make sure you have one text editor in place and you have
enough experience to write a computer program, save it in a file, compile it and finally
execute it.

(b)The C Compiler

The source code written in source file is the human readable source for your program. It needs
to be "compiled" into machine language so that your CPU can actually execute the program as
per the instructions given.
The compiler compiles the source codes into final executable programs. The most frequently
used and free available compiler is the GNU C/C++ compiler, otherwise you can have
compilers either from HP or Solaris if you have the respective operating systems.

The following section explains how to install GNU C/C++ compiler on WINDOWS
especially since it is the system that we are using. We keep mentioning C/C++ together
because GNU gcc(GNU Compiler Collection) works for both C and C++ programming
languages

2.5- FULL STRUCTURE OF A C PROGRAM:


Structure of C program is defined by set of rules called protocol, to be followed by
programmer while writing C program. All C programs are having sections/parts which are
mentioned below.

1. Documentation section
2. Link Section
3. Definition Section
4. Global declaration section
5. Function prototype declaration section
6. Main function
7. User defined function definition section
EXAMPLE C PROGRAM TO COMPARE ALL THE SECTIONS:
You can compare all the sections of a C program with the below C program.
DESCRIPTION FOR EACH SECTION OF THE C PROGRAM:
 Let us see about each section of a C basic program in detail below.
 Please note that a C program mayn’t have all below mentioned sections except main
function and link sections.
 Also, a C program structure mayn’t be in below mentioned order.

Sections Description

We can give comments about the program, creation


or modified date, author name etc in this section. The
characters or words or anything which are given
Documentation
between “/*” and “*/”, won’t be considered by C
section
compiler for compilation process. These will be
ignored by C compiler during compilation.
Example : /* comment line1 comment line2 comment
3
*/

Header files that are required to execute a C program


Link Section
are included in this section

In this section, variables are defined and values are


Definition Section
set to these variables.

Global Global variables are defined in this section. When a


declaration variable is to be used throughout the program, can be
section defined in this section.

Function
Function prototype gives many information about a
prototype
function like return type, parameter names used
declaration
inside the function.
section

Every C program is started from main function and


Main function this function contains two major sections called
declaration section and executable section.

User can define their own functions in this section


User defined
which perform particular task as per the user
function section
requirement.

KEY POINTS TO REMEMBER IN C PROGRAMMING BASICS:


1. C programming is a case sensitive programming language.
2. Each C programming statement is ended with semicolon (;) which are referred as
statement terminator.
3. printf() command is used to print the output onto the screen.
4. C programs are compiled using C compilers and displays output when executed.

You might also like