You are on page 1of 9

C Language:

C is a general-purpose, high-level language that was originally developed by


Dennis Ritchie to develop the UNIX operating system at Bell Labs. C was
originally first implemented on the DEC PDP-11 computer in 1972.

In 1978, Brian Kernighan and Dennis Ritchie produced the first publicly available
description of C, now known as the K&R standard.

Why to use C:
C language is used for developing system applications that forms 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
 Spread sheets
 Operating system development
 Compilers and Assemblers
 Network drivers
 Interpreters

Features of C language:

1) Low Level Language Support: C Provides Low level Language


Features that are generally provided by programming language.C is
closely related to Lower level Languages.It is easier to write assembly
language codes in C Language.
2) Portability:C programs can be run on any complier with liitle or no
modification.Compliers and preprocessors make it possible for c
programs to run it on different pc’s.
3) PowerFul:It provides wide variety of datatypes,functions,Controls and
loop control statements.
4) BitManipulation:C programs can be manipulated using bits.We can
perform different operations at bit level.We can manage memory
representation at bit level.
5) High Level Features:It is more user friendly when compared with
previous languages such as languages like BCPL,Pascal and other
programming languages never provide such great features to manage
the data.
6) Modular Programming:It consists of different modules that are
integrated to gether to form a complete program.
7) Efficient use of pointers:Pointers has direct access to memory.
C Supports efficient use of pointers.

C language is belonging to?

S.no High Level Middle Level Low Level

Middle level
languages don’t Low level
High level
provide all the languages
languages
built-in provides
provides almost
functions found nothing other
everything that
in high level than access
1 the programmer
languages, but to the
might need to
provides all machines
do as already
building blocks basic
built into the
that we need to instruction
language
produce the set
result we want

Examples:
2 C, Assembler
Java, Python

C language is a structured language :

Structure Object
S.no Non structure
oriented oriented

In this type of In this type of There is no


1 language, large language, specific
programs are programs are structure for
divided into divided into programming
small objects this language
programs
called
functions

Prime focus is
Prime focus is on the data
on functions that is being
2 and procedures operated and N/A
that operate on not on the
data functions or
procedures

Data moves
Data is hidden
freely around
and cannot be
the systems
3 accessed by N/A
from one
external
function to
functions
another

Program Program
structure structure
4 follows “Top follows N/A
Down “Bottom UP
Approach” Approach”

Examples:
C++, JAVA BASIC,
5 C, Pascal, and C# (C COBOL,
ALGOL and sharp) FORTRAN
Modula-2

Basic structure of 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 basic structure program Documentation section

Date : 01/01/2012
*/
#include <stdio.h> /* Link section */
int total = 0; /* Global declaration and definition section */
int sum (int, int); /* Function declaration section */
int main () /* Main function */
{
printf ("This is a C basic program \n");
total = sum (1, 1);
printf ("Sum of two numbers : %d \n", total);
return 0;
}
int sum (int a, int b) /* User defined function */
{ /* definition section */
return a + b;
}

S.No 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
Documentation are given between “/*” and
1
section “*/”, won’t be considered by
C 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
2 Link Section to execute a C program are
included in this section
In this section, variables are
Definition
3 defined and values are set to
Section
these variables.
Global variables are defined in
Global this section. When a variable
4 declaration is to be used throughout the
section program, can be defined in
this section.
Function prototype gives
Function
many information about a
prototype
5 function like return type,
declaration
parameter names used inside
section
the function.
Every C program is started
from main function and this
6 Main function function contains two major
sections called declaration
section and executable section.
User can define their own
User defined functions in this section which
7
function section perform particular task as per
the user requirement.

C – Data Types
 C data types are defined as the data storage format that a variable can store
a data to perform a specific operation.
 Data types are used to define a variable before to use in a program.
 Size of variable, constant and array are determined by data types.
C – data types:

There are four data types in C language. They are,


S.no Types Data Types

1 Basic data types int, char, float, double

Enumeration data
2 Enum,typedef
type

pointer, array, structure,


3 Derived data type
union

4 Void data type void

Character set of C Language:

C compiler allows to use many no. of characters :

Lower case letters : a b c … z

Upper case letters : A B C….Z

Digits : 0 1 2 3 …9

Other characters : + - * ( ) & % $ # { } [ ]’ “ : ; etc.

White space characters : blank, new line, tab space etc.

Conversion Characters( format specifiers):

Conversion characters or format specifiers are used to provide the format

for the value to be print.. it has a prefix ‘ % ‘ and followed by a specifier.

%d : prints integer

%f : prints float

%lf : prints double

%c : prints character
%s : prints string

%o : prints octal value

%u : prints unsigned integer

%x : prints hexa decimal value

Data type Memory Format specifier :

Int ------------------ 2 bytes ----------------------%d,%i

Char---------------1 bytes-------------------------%c

Float---------------4 bytes--------------------------%f

Double-------------8 bytes----------------------- %f

String--------------Size of char array------------%s

Unsigned int------ 2 bytes -----------------------%u

Long unsigned int--8bytes------------------------%lu

long int----------------4 bytes-----------------------%ld

C Tokens:

C tokens includes identifiers, keywords, variables, constants

and operators.

Identifiers : the names of variables, functions, labels and various other

user defined items are called as identifiers. Identifiers contains alphabets,

digits and underscore. It can’t include spaces. It starts with alphabet.

Ex: lcm( ), ab_cd, pi,r etc.


Keywords: keywords(reserved words) are defined by C compiler and

each word has different meaning, these can not used as names of

variables, functions or labels.

Ex: auto, for, switch, do, while, case, else, goto etc.

Variables: these are defined by user and used in program. It is composed

of letters, digits and underscore. These are instances of data types.

Ex: int a,x1,a_b ; float pi,r; char x1;

Constants : constants means which never changes it’s value.

Ex: int x=10,

float a=2.35;

char c=’a’;

char name[ ]=”vijay”;

operators: C allows several types of operators such as arithmetic( +,-

.*,/,%) and other operators.

Escape Sequence Characters:

Escape
Meaning
sequence

\\ \ character

\' ' character

\" " character

\? ? character

\a Alert or bell

\b Backspace
\f Form feed

\n Newline

\r Carriage return

\t Horizontal tab

\v Vertical tab

\ooo Octal number of one to three digits

\xhh . . . Hexadecimal number of one or more digits

Keywords:
The following list shows the reserved words in C. These reserved words may not be used as
constant or variable or any other identifier names.

auto else long switch


break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double

You might also like