Handout C Lecture 1 Part 1 Intro To C 1 AA NEW Date 27-06-2023

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

27-Jun-23

Chapter 1. Introduction to C
B.Sc. Mathematics SEMESTER -5
 What is C ?
PROGRAMMING IN C
 Brief history and origin of Programming Languages.
Unit 1: Introduction to C  Introduction to C / The C Character Set
Lecture 1 Part - 1  Constants, Variables and Keywords
 Types of C Constants
BY  Rules for Constructing Integer Constants
 Rules for Constructing Real Constants
Jignasu N. Chauhan  Rules for Constructing Character Constants
Head and Associate Professor
Department of Mathematics
 Types of C Variables
Shree Manibhai Virani & Smt. Navalben Virani Science College  Rules for Constructing Variable Names
An Autonomous College - Affiliated to Saurashtra University
"Yogidham Gurukul“ Kalawad Road  C Keywords
Rajkot. Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 2

Chapter 1. Introduction to C ENIAC ( Electronic Numerical Integrator And Computer)


• ENIAC's design and construction was
 The First C Program financed by the United States Army.
 Compilation and Execution
• Giant Brain - The completed machine
 Receiving Input
 C Instructions
was announced to the public the
 Type Declaration Instruction evening of February 14, 1946.
 Arithmetic Instruction • ENIAC was conceived and designed
 Integer and Float Conversions
by John Mauchly and J. Presper
 Type Conversion in Assignments
Eckert of the University of
 Hierarchy of Operations
 Control Instructions in C
Pennsylvania.
Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics, Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College,
Virani Science College, Rajkot. 3 Rajkot. 4

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 1
27-Jun-23

ENIAC ( Electronic Numerical Integrator And Computer) ENIAC ( Electronic Numerical Integrator And Computer)
• ENIAC contained 17,468 vacuum tubes, • Took up 1800 square feet (167 m2), and
• 7,200 crystal diodes, 1,500 relays, 70,000 • Consumed 150 kW of power.
resistors,
• This led to the rumor that whenever
• 10,000 capacitors and
the computer was switched on, lights
• Around 5 million hand-soldered joints.
in Philadelphia dimmed.
• It weighed more than 30 short tons (27 t),
• Input was possible from an IBM card
• It was roughly 8 by 3 by 100 feet (2.4 m × 0.9
reader, and an
m × 30 m),
• IBM card punch was used for output.

Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College,
Rajkot. 5 Rajkot. 6

Atanasoff–Berry computer Atanasoff–Berry computer


The Atanasoff–Berry computer (ABC)  Most would probably credit John
was the first automatic electronic Mauchly and J. Presper Eckert, creators of
digital computer, the ENIAC,
 Iowa State mathematics and physics
An early electronic digital computing
professor John Vincent Atanasoff for his
device that has remained somewhat work with the 'ABC,' with the help of
obscure. graduate student Clifford Berry.
To say that it was the first is a debate  Conceived in 1937, the machine was not
among historians of computer programmable, being designed only to
technology. Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics,
solve systems of linear equations.
Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 7 Virani Science College, Rajkot. 8

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 2
27-Jun-23

Atanasoff–Berry computer History of Computers and Languages.


It was successfully tested in 1942. Pascle’s Calculator.
However, its intermediate result Charles Babbage
storage mechanism, a paper card
John Van Newmann
writer/reader, was unreliable,
ADA – First Lady Programmer.
Algorithm / Flowchart

Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College,
Virani Science College, Rajkot. 9 Rajkot. 10

Computer / Data / Information Computer / Data / Information


An electronic device which is capable  Data:-
of receiving information (data) in a 1. Facts and statistics collected together for
particular form and of performing a reference or analysis.
sequence of operations in accordance 2. Synonyms: facts, figures, statistics,
with a predetermined (but variable) details, particulars, specifics, features;
set of procedural instructions 3. Things known or assumed as facts,
(program) to produce a result in the making the basis of reasoning or
form of information or signals. calculation.
Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 11 Virani Science College, Rajkot. 12

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 3
27-Jun-23

Information Information
 1. Knowledge derived from study, 4. The act of informing or the
experience, or instruction. condition of being informed;
 2. Knowledge of specific events or communication of knowledge: Safety
situations that has been gathered or instructions are provided for the
received by communication; information of our passengers.
intelligence or news. See Synonyms at
knowledge. 5. Computer Science Processed,
 3. A collection of facts or data:
stored, or transmitted data.
statistical information.
Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College,
Rajkot. 13 Rajkot. 14

Data processing Block diagram of a computer system


 Data processing is, broadly, "the collection and
manipulation of items of data to produce meaningful
information."

Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College,
Virani Science College, Rajkot. 15 Rajkot. 16

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 4
27-Jun-23

Memory Units Memory Units

Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 17 Virani Science College, Rajkot. 18

Computer Languages
MEMORY UNITS
 Machine Language:- -
 A set of instructions for a specific central
processing unit, designed to be usable by a
computer without being translated. Also called
machine code.
 An assembly language is a low-level
programming language for a computer, or other
programmable device, in which there is a very
strong (generally one-to-one) correspondence
between the language and the architecture's
machine code instructions.
Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 19 Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, 20
Rajkot.

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 5
27-Jun-23

Computer Languages Computer Languages


 Each assembly language is specific to a particular HIGH-LEVEL LANGUAGES
computer architecture, in contrast to most high-
level programming languages, which are generally A high-level language is an
portable across multiple architectures, but advanced computer programming
require interpreting or compiling.
language that isn't limited by the
 Assembly language is converted into executable
machine code by a utility program referred to as computer, isn't designed for a
an assembler; specific job, and is easier to
 The conversion process is referred to as assembly,
or assembling the code.
understand.

Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, 21 Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, 22
Rajkot. Rajkot.

Computer Languages Computer Languages


 The first high-level programming languages Such languages are considered
were designed in the 1950s. Now there are
high-level because they are closer
dozens of different languages, including
Ada, Algol, BASIC, COBOL, C, C++, to human languages and further
FORTRAN, LISP, Pascal, and Prolog. from machine languages.
 A programming language such as C, In contrast, assembly languages are
FORTRAN, or Pascal that enables a
programmer to write programs that are
considered low-level because they
more or less independent of a particular are very close to machine
type of computer. languages.
Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, 23 Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, 24
Rajkot. Rajkot.

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 6
27-Jun-23

Computer Languages History of Computer Languages.


The main advantage of high-level  Algorithm
 An algorithm is a well-defined procedure that allows a
languages over low-level languages computer to solve a problem.
 Another way to describe an algorithm is a sequence of
is that they are easier to read, write, unambiguous instructions.
 An algorithm “is a step-by-step procedure for calculations.

and maintain.  A Programming Language


 A programming language is a vocabulary and set of
grammatical rules for instructing a computer or computing
Ultimately, programs written in a device to perform specific tasks
 Examples of programming language
high-level language must be  FORTRAN – FORmula TRANslation
 COBOL – Common Business Oriented Language.
translated into machine language  BASIC – Beginner’ All Purpose Symbolic Instruction Code
 ALGOL – ALGOrithmic Language.
by a compiler or interpreter.  PL/1 – Programming Language – 1

Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics,
Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College, 25 Virani Science College, Rajkot. 26
Rajkot.

History of Computers and Languages. History of Computers and Languages.


Name of ALGOL 60 (1960) BCPL (1967)
Full form / Name Purpose CPL (1963)
language International
- Cambridge university)
Martin Richards at
Committee Cambridge University
Combined Programming
FORTRAN FORmula TRANslation To solve Engineering, Scientific Too abstract & Language
Basic Combined
Programming
and Mathematical problems Too general Hard to learn Language
Very difficult to Too less powerful &
Difficult to understand.
learn. Too specific.
COBOL Common Business For commercial applications
Oriented Language.

BASIC All Purpose Symbolic For beginners C language (1972) B language (1970)
Instruction Code Denis Ritchie of Ken Thompson of
AT and T’s bell laboratory AT and T’s bell laboratory
ALGOL 60 ALGOrithmic To invent general purpose Powerful, simple Too specific &
Language. language common language & easy to learn language. Less powerful
Programming Language – 1
PL/1
Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 27 Virani Science College, Rajkot. 28

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 7
27-Jun-23

What is C? History and Origin of C language? What is C? History and Origin of C language?
 Developed at AT & T’s Bell Laboratories of USA  Thus, without any advertisement C’s reputation
in 1972.  spread and its pool of users grew.
 Designed and written by a man named Dennis  Ritchie seems to have been rather surprised that
Ritchie. so many programmers preferred C to older
 In the late seventies C began to replace the more languages like FORTRAN or PL/I, or the newer
familiar languages of that time like PL/I, ALGOL, ones like Pascal and APL.
etc.  Popular is because it is Reliable, Simple And
 No one pushed C. Easy To Use.
 It wasn’t made the ‘official’ Bell Labs language.  A language that has survived for more than 3
decades has to be really good.
Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics, Presentation Prepared by Jignasu N. Chauhan, Head and Asso. Prof., Department of Mathematics, Virani Science College,
Virani Science College, Rajkot. 29 Rajkot. 30

Features of C Programming Language


Machine independent Portable language
Machine independent Portable language

Portability

Modular and Structured Language

Simple and Efficient

Very good speed

Existence of rich libraries

Case Sensitive
Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 31 Virani Science College, Rajkot. 32

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 8
27-Jun-23

Machine independent Portable language

Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 33 Virani Science College, Rajkot. 34

Learning C Language
Steps to learn any language

Alphabets Words Sentences Paragraphs

Steps to learn C language

Constants
Alphabets, Digits,
Special Symbols
Variables, Instructions Program
Keywords

Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 35 Virani Science College, Rajkot. 36

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 9
27-Jun-23

Character Set of C Language


Character Set of C Language Special Characters

! Exclamation mark _ Underscore


# Number sign
Types Character Set + Plus sign
$ Dollar sign
Lowercase Letters a, b, c, …,x, y, z
% Percent sign
| Vertical bar
Uppercase Letters A, B, C, …,X, Y, Z

Digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ^ Caret \ Backslash


White Spaces New line, Blank Space , Horizontal
tab, Carriage Return and Form feed.
& Ampersand
` Apostrophe
* Asterisk

( Left parenthesis - Minus sign


) Right parenthesis
Presentation Prepared by Jignasu N. Chauhan,
=
Presentation Prepared by Jignasu N. Chauhan,
Equal to sign
Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 37 Virani Science College, Rajkot. 38

Character Set of C Language


Special Characters Character Set Of C language
{ Left brace
> Closing angle bracket
} Right brace
(or greater than sign)
[ Left bracket
? Question mark
] Right bracket
, Comma
: Colon
. Period
” Quotation mark
/ Slash
; Semicolon
@ at-sign
< Opening angle bracket
~ tilde
(or less than sign)
Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 39 Virani Science College, Rajkot. 40

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 10
27-Jun-23

Constants in C language Types of Constants in C language


 In computer programming, a constant is an
identifier whose associated value cannot be
altered(changed) by the program during its
execution.
 In programming, a constant is a value that never
changes.
 The other type of values that programs use is
variables, symbols that can represent different
values throughout the course of a program.

Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 41 Virani Science College, Rajkot. 42

Types of Constants in C language Types of Constants in C language


Character
Real Constants
Constants

Fractional Form Exponent Form Single String


of Real of Real Character Character
Constants Constants Constant Constants

Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 43 Virani Science College, Rajkot. 44

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 11
27-Jun-23

Rules for Constructing Integer Constants. Rules for Constructing Integer Constants.
(a) An integer constant must have at least one digit.  The range of an Integer constant depends upon
(b) It must not have a decimal point. the compiler.
(b) It can be either positive or negative.  For a 16-bit compiler like Turbo C or Turbo C++
(c) If no sign precedes an integer constant it is assumed to the range is –32768 to 32767.
be positive (Default Sign is Positive)  Ex.: 786, +108, -22740, -5702, 0 … etc.
(e) No commas or blanks are allowed within an No Rule Integer
integer constant. 1 Decimal Point Not Allowed
(f ) The allowable range for integer constants is -32768 2 Sign Positive or Negative
to 32767. 3 Default Sign Positive
4 No of Digits At least 1
(g) 2 bytes in memory is allocated for Integer Value.
5 Min Value -32768
6 Max Value +32767

Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 45 Virani Science College, Rajkot. 46

Rules for Constructing Real Constants in Fractional form Rules for Constructing Real Constants in Exponential Form
(Floating Point constants). (Floating Point constants).

Real constants expressed in fractional form: Real constants expressed in Exponential Form :-
Rules:-  This form is used if the value of the constant is either too
• A real constant must have at least one digit. small or too large.
 In exponential form of representation, the real constant is
• It must have a decimal point.
 represented in two parts.
• It could be either positive or negative.
 The part appearing before ‘e’ is called MANTISSA,
• Default sign is positive.  whereas the part following ‘e’ is called EXPONENT.
• No commas or blanks are allowed
within a real constant. (MANTISSA_part)e(EXPONENT_PART)
Ex.: +3.1415, 589.0, -67.97, -37.0278
Range of Real constants (expressed in fractional form) is
-3.4e38 to 3.4e38

Presentation Prepared by Jignasu N. Chauhan, Presentation Prepared by Jignasu N. Chauhan,


Head and Asso. Prof., Department of Mathematics, Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 47 Virani Science College, Rajkot. 48

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 12
27-Jun-23

Rules for Constructing Real Constants in Exponential Form


(Floating Point constants).

Rules:-
 The mantissa part and the exponential part should be
separated by a letter e.
 The mantissa part may have a positive or negative sign.
 Default sign of mantissa part is positive.
 The exponent must have at least one digit, which must
be a positive or negative integer.
 Default of sign exponent is positive.
 Range of real constants expressed in exponential form is -
3.4e38 to 3.4e38.
Ex.: +97.57e-7, 3.84e6, -0.032e+4, -2.33e-21
Range of Real constants (expressed in exponent form) is -3.4e38 to 3.4e38
Presentation Prepared by Jignasu N. Chauhan,
Head and Asso. Prof., Department of Mathematics,
Virani Science College, Rajkot. 49

Presentation Prepared by Jignasu N. Chauhan, Head and Asso.


Prof., Department of Mathematics, Virani Science College,
Rajkot. 13

You might also like