You are on page 1of 6

Structured Programming through ‘C’

Introduction C-Programming Language


History of C-Language

 C language is a structure oriented programming language, developed at Bell Laboratories


in 1972 by Dennis Ritchie
 C language features were derived from earlier language called “B” (Basic Combined
Programming Language – BCPL)
 C language was invented for implementing UNIX operating system
 In 1978, Dennis Ritchie and Brian Kernighan published the first edition “The C
Programming Language” and commonly known as K&R C
 In 1983, the American National Standards Institute (ANSI) established a committee to
provide a modern, comprehensive definition of C. The resulting definition, the ANSI
standard, or “ANSI C”, was completed late 1988.

Features of C-Language

The most important features of C language are as follows.

1. Modularity.

2. Portability.

3. Middle Level.

4. Powerful

5. Efficient Use of Pointers.

6. Flexibility.

Modularity: Ability to breakdown a large module into manageable sub modules called as
modularity that is an important feature of structured programming languages.

Advantages:

1. Projects can be completed in time.

2. Debugging will be easier and faster.

Portability:

 C Programs are portable i.e they can be run on any Compiler with Little or no
Modification.
 Compiler and Preprocessor make it Possible for C Program to run it on Different PC.

Department of Computer Science, BVRICE Page 1


Structured Programming through ‘C’

Middle Level:

‘C’ is also called as middle level language because programs written in ‘c’ language run
at the speeds matching to that of the same programs written in assembly language so ‘c’
language has both the merits of high level and middle level language and because if this feature
it is mainly used in developing system software.

Powerful

 Provides Wide verity of ‘Data Types‘


 Provides Wide verity of ‘Functions’
 Provides useful Control & Loop Control Statements

Efficient Use of Pointers:

 Pointers have direct access to memory.


 C Supports efficient use of pointer.

Flexibility

This feature refers to the programmer’s involvement and control on the language. There
are number of reserve words in C Language which help the programmer to take control over the
usage of language and modified the structure of program.

Applications of C-Language

C Programming is best known programming language. C Programming is near to


machine as well as human so it is called as Middle level Programming Language. C
Programming can be used to do verity of tasks such as networking related,OS related.

Application of C Programming are listed below

1. C language is used for creating computer applications


2. Used in writing embeddedsoftware’s.
3. Firmware for various electronics, industrial and communications products which use
micro-controllers.
4. It is also used in developing verification software, test code, simulators etc. for various
applications and hardware products.
5. For Creating Compiles of different Languages which can take input from other language
and convert it into lower level machine dependent language.
6. C is used to implement different Operating System Operations.
7. UNIX kernel is completely developed in C Language.

Department of Computer Science, BVRICE Page 2


Structured Programming through ‘C’

Structure of a C-Program

The structure of a C program is a protocol (rules) to the programmer, while writing a C


program. The general basic structure of C program is shown in the figure below.

Documentations or Commenting Section

The documentation section consist of a set of comment lines giving the name of the
program, the author name and other details, which the programmer would like to use later.

Preprocessor Statements or Header File Section

The preprocessor statement begins with # symbol and is also called the preprocessor
directive. These statements instruct the compiler to include C preprocessors such as header files
and symbolic constants before compiling the C program. Some of the preprocessor statements
are listed below.

Department of Computer Science, BVRICE Page 3


Structured Programming through ‘C’

Global Declaration Section

The variables are declared before the main ( ) function as well as user defined functions is
called global variables. These global variables can be accessed by all the user defined functions
including main ( ) function.

The main ( ) function

Each and Every C program should contain only one main ( ). The C program execution
starts with main ( ) function. No C program is executed without the main function. The main ( )
function should be written in small (lowercase) letters and it should not be terminated by
semicolon.Main ( ) executes user defined program statements, library functions and user defined
functions and all these statements should be enclosed within left and right braces.

Local Declarations

The variable declaration is a part of C program and all the variables are used in main ( )
function should be declared in the local declaration section is called local variables.

Program statements

These statements are building blocks of a program. They represent instructions to the
computer to perform a specific task (operations). An instruction may contain an input-output
statements, arithmetic statements, control statements, simple assignment statements and any
other statements and it also includes comments that are enclosed within /* and */ . The comment
statements are not compiled and executed and each executable statement should be terminated
with semicolon.

User defined functions

These are subprograms, generally, a subprogram is a function and these functions are
written by the user are called user defined functions. These functions perform user specific tasks
and this also contains set of program statements. They may be written before or after a main ()
function and called within main () function. This is an optional to the programmer.

Rules to write C program

The following are some of rule to write C programs.

1. All C statements must end with semicolon.


2. C is case sensitive. That is upper case and lower case letter are distinct.
3. A C statement can be written in one or it can split into multiple lines.
4. Braces must always match upon pairs, i.e., every open brace { must have a matching
closed brace }.

Department of Computer Science, BVRICE Page 4


Structured Programming through ‘C’

5. No restriction in using blank spaces or blank line in program segments. But spaces not
allowed within variable, constant or keyword.
6. Comments cannot be nested. For example
/* A simple ‘C’ program, /* it prints a message */ */ is not valid.
7. A comment can be split into more number of lines.
8. The global variables can be declared outside of all functions.

Steps for writing & execution a simple C program

There are three steps in developing C program.

1. Creation of Source Program


2. Compilation of program
3. Program execution

Creation of source program:

Create a text file using any word processing software with its name end with a C
extension and type a C program in that file. Various C-compilers are available under DOS
wizard. Quick C, Microsoft C, Turbo C, ANSI C etc are examples for the C-Compilers.

Compilation of program:

The compilation command under Turbo C

Alt+F9

For example, if file name is “Sample.c”, open the file using Turbo C editor and press
Alt+F9 in keyboard. If no errors found it will produce object file i.e., Sample.obj(It is the
machine understandable file).

Program execution:

In Turbo C environment, the RUN option will do the execution of program. Ctrl+F9 is
short cut key from keyboard to run program. After completing the execution of the C-Program, it
generates the desired output to our program with respect to the given input. And the resultant file
is Sample.exe.

C-Character Set

The character set is used to form words, numbers and expressions depending upon the
computer on which the programs run. The characters in the C are categorized in the following
way.

Department of Computer Science, BVRICE Page 5


Structured Programming through ‘C’

Letters  A to Z, a to z.

Digits  0 to 9 decimal digits.

Some Special Symbols as follows.

Meani
Symbol Symbol Meaning Symbol Meaning Symbol Meaning
ng
Lest
~ Tilde - Minus sign ( ; Semicolon
parenthesis
Exclam Opening
Equal to Right
! ation = ) < angle
sign parenthesis
mark bracket
Closing
Numbe
# { Left brace _ Underscore > angle
r sign
bracket
Dollar Question
$ } Right brace + Plus sign ?
sign mark
Percent Left Vertical
% [ | , Comma
sign bracket bar
Right
^ Caret ] \ Backslash . Period
bracket
Ampers
& : Colon ` Apostrophe / Slash
and
Asteris Quotation
* "
k mark

Delimiters in C

A delimiter is a unique character or series of characters that indicates the beginning or


end of a specific statement, string or function body set.

The following tables explain about the delimiters in C.

Delimiter Purpose
: Useful for labeling
; Statement termination symbol
{} Justifies the scope of the variable
() To define function and function call
[] Used for array declaration.
# Preprocessor Directive.
, Variable Separator.

Department of Computer Science, BVRICE Page 6

You might also like