0% found this document useful (0 votes)
6 views

C_Tutorial_Day_2

Uploaded by

Deepak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

C_Tutorial_Day_2

Uploaded by

Deepak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Programming With C-Introduction

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.

Created and verified By: B. K. Deepak 13


Dated:20/12/2004
Rev:00
Programming With C-Introduction

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.

Created and verified By: B. K. Deepak 14


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

Variables and Expressions

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:

, comma . period ; semicolon : colon # pound ’ Apostrophe


” quotation ! exclamation | Vertical bar ~ tilde < Less than > Greater than
_ underscore $ dollar % percent ? question & ampersand ^ Caret
* asterisk ( left parenthesis ) right parenthesis + Plus - Minus [ Left bracket
] Right bracket { Left braces } Right braces / slash \ Back slash

White Space Character: blank space, new line, carriage return, form feed, horizontal tab, vertical tab

Created and verified By: B. K. Deepak 15


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

Identifiers and keywords


Identifiers are used to identify or name a location that holds values used in programs such as variables,
symbolic constants, functions etc. Keywords have predefined meanings and can not be changed by user.
The following keyword predefined in C language:
int short long signed unsigned float double char void
auto static extern register
if else switch case default break goto continue for
while do return
struct union enum typedef sizeof const volatile
Rules for creating identifier
 Identifier names may be a sequence of letters (uppercase and lowercase), sequence of letters and di-
gits.
 Must begin with an letter.
 The underscore (_) character is considered as a letter that can be used in identifier.
 It should not be same as keyword.
 C is case sensitive i.e. upper case and lower case are treated differently).
 The name can be of any length but the first 31 characters are significant in most of the compliers.
 It is advised not to start identifier name with ( _ ) underscore.

Created and verified By: B. K. Deepak 16


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

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

Created and verified By: B. K. Deepak 17


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

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

Created and verified By: B. K. Deepak 18


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

Rules for Octal Integer constants


 At least two digits in which first character should always be 0.
 Only digits through 0,1,2,3,4,5,6,7 are allowed.
 + or – sign is allowed but it should use as prefix to indicate positive or negative
 No any other characters are allowed.
 Qualifiers if any can be used such as U, L and UL or u, l and ul
Exercise: Which among following are invalid and why?
0234 044 079 067
If x=-067 then it will be represented by computer in
Octal as 177711
Decimal as -55
Hexadecimal as FFC9
Why?

Created and verified By: B. K. Deepak 19


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

Rules for Hexadecimal Integer constants


 At least three letters in which first two letter should always be 0x or 0X.
 Other letters can be used are 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,a,b,c,d,e,f.
 + 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?
0x37 0xAF 0XFF67 0X77FX -0x37
If x=-0x37 then its values in
Decimal integer is -55
Octal integer is 177711
Hexadecimal integer is FFC9
Why?

Created and verified By: B. K. Deepak 20


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

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.

Created and verified By: B. K. Deepak 21


Dated:20/12/2004
Rev:00
Programming With C-Operators and Expressions

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.

Created and verified By: B. K. Deepak 22


Dated:20/12/2004
Rev:00

You might also like