C_Tutorial_Day_2
C_Tutorial_Day_2
Introducing C
A Historical Overview
C is a general purpose computer programming language. It was originally created by Dennis M. Ritchie
(1972 AD) for specific purpose of writing system software. It was developed along with the UNIX operating
system; it is strongly associated with UNIX.
This famous operating system at that time in its infancy; it had recently been written for a discarded DEC
PDP7 computer by Ken Thompson, an electrical engineer and a colleague of Ritchie’s at Bell labs. Thomas
had written the first UNIX in a language, he called B. Another language developed at that time was B Com-
puter Programming Language – BCPL, by Martin Richards. The intention of these programmers is to make
an OS that can be ported on any other, architecturally dissimilar machine. It was not possible to develop
such an OS using Assembly language. B language was further modified by Ritchie and named it as C lan-
guage. The C is successor of B as well as BCPL.
C has all the advantages of assembly language, with none of its disadvantage; and it has all the significant
features of modern high level language. Today it is a language of choice for systems programming, for the
development of 4GL packages such as Dbase, and also for creation of user friendly interfaces for special
application.
Features of C
Portability: Programs written in HLL can be compiled and executed in different computers and operating sys-
tems if compilers are available for these systems.
Flexibility: C combines the convenience and portable nature of a high level language with the flexibility of low
level language. Therefore it can be called as a middle level language.
Wide acceptability: C becomes a language that is widely acceptable in the community of programmers. It
is suitable for system level as well as for application level.
Character Set
The C character set consists of upper and lower case alphabets, digits special characters and white spaces.
Alphabets:
A B C D E F ……………………… X Y Z (UPPER CASE)
a b c d e f g ………………………. x y z (lower case)
Digits:
0 1 2 3 4 5 6 7 8 9 (digits)
Special Characters:
White Space Character: blank space, new line, carriage return, form feed, horizontal tab, vertical tab
Exercise:
Which among them are invalid identifier and why?
a. _first
b. 1st
c. first
d. area of circle
e. area_of_circle
f. int
g. Int
h. Float
i. integer
j. long
Constants
Constants are the fixed values that we have to use in the program such as
5 9 9.5 “Deepak Kumar” ‘d’ 9.05x10-7
0567 0XFF23
5 and 9 is an decimal integer number constant
9.5 and 9.05x10-7 is real number constant
“Deepak Kumar” is a string constant
and ‘d’ is a character constant
0567 is an octal integer constant
0XFF23 is a Hexadecimal Integer constant
Rules for decimal Integer constants
At least one digit.
Only digits through 0,1,2,3,4,5,6,7,8,9 are allowed.
+ or – sign is allowed but it should use as prefix to indicate positive or negative
No any other characters are allowed.
Exercise: Which among following are invalid and why?
234 1,234 44.0 0 79
Real Constants
Real numbers are those numbers in which we can represent values with fractional part. Real number
represented using two forms
1. Fractional form 2. Exponential form
Rules for fractional form real number
At least one digit with decimal point
Digit allowed are 0,1,2,3,4,5,6,7,8,9 only
+ or – sign can be prefixed the number to indicate as positive or negative number
No any other characters are allowed.
Exercise: Which among following are invalid and why?
0 0.0 0. .0 .05 50. 50.5 +56.789 56.789- 56,789.89
Rules for exponential form
Fractional number when very small or large then it is better to represent it in exponential form
e.g. 0.000045678 can be written as 4.5678x10-5
the above number is in two parts 4.5678 is known as mantissa part and -5 is exponent part. It is represented
in computer as mantissa_part E ± exponent_part i.e. 4.5678 e -05
mantissa part follow rules of real number(fraction form) whereas exponent part follows rules of integer num-
ber.
String Constants
Character data can be stored in computer for manipulation and for printing output with message. Single cha-
racter when used in program is known as character constant while multiple characters is known as character
string or only string.
Character data stored in computer as using within single quote (apostrophe)
’x’ ’a’ ’Y’ ’N’ ’n’ ’5’
String data stored in computer written as using within double quote
”Deepak Kumar” ”x” ”Key Strokes” ”302”
Boolean constants
Boolean values are true and false which is represented in C language as non zero number and zero.
The basic data which can not be break further is known as primitive data type. Other types of data can be
created with the help of primitive data is known as non primitive data type.