2. To study…..
4th Dec. 2018Dr. Lothe Savita A.
2
Introduction
Basic Elements and operators
Data types
C program and I/O statements
3. Introduction
4th Dec. 2018Dr. Lothe Savita A.
3
C is programming language developed at AT & T’s
Bell Laboratories ---USA – in 1972.
Dennis Ritchie.
4. History
4th Dec. 2018Dr. Lothe Savita A.
4 Year Language Developed By Remarks
1960 ALGOL International
Committee
Too general, too
abstract
1963 CPL Cambridge
university
Hard to learn, difficult
to implement
1967 BCPL Martin Richards at
Cambridge
University
Could deal with a
specific problems
1970 B Ken Thompson at
AT & T
Could deal with a
specific problems
1972 C Dennis Ritchie at
AT & T
Lost generality of BCPL
and B restored.
5. Where C stands
4th Dec. 2018Dr. Lothe Savita A.
5
Problem oriented Lang. / High level Lang.
Better programming efficiency i.e. faster program
development
Machine oriented Lang. / Low level Lang.
better machine efficiency i.e. faster program
execution.
C stands in between these 2 categories.
6. Started with C
4th Dec. 2018Dr. Lothe Savita A.
6
Learning English Lang.
Steps in learning C
Alphabets Words Sentences paragraph
Instructions
Constants
Variables
Keywords
Alphabets
Digits
Special sym.
7. C Character Set
4th Dec. 2018Dr. Lothe Savita A.
7
Alphabets : A, B, …………..Y,Z
a,b,c, …………..y,z
Digits : 0,1,…………………9
Special symbols : ~ ` ! @ # $ % ^ …..……
8. Constants, Variables & keywords
4th Dec. 2018Dr. Lothe Savita A.
8
A constant is a quantity that doesn't change.
Stored at locations in the memory of the computer.
9. 4th Dec. 2018Dr. Lothe Savita A.
9
C constant
Integer
Real
character
Primary Secondary
Array
Pointer
Structure
Union
Enum
10. Rules for constructing integer constants
4th Dec. 2018Dr. Lothe Savita A.
10
An integer constant must have at least one digit.
It must not have a decimal point.
It could be either positive or negative.
If no sign precedes an integer constant it is assumed
to be positive.
No commas or blanks are allowed.
Range is -32768 to +32767.
Eg : 426
+782
11. Rules for constructing Real Constants
4th Dec. 2018Dr. Lothe Savita A.
11
Called as floating point constants.
Written into 2 forms:
Fractional form
Exponential form
12. Rules for constructing real constants in
fractional form:
4th Dec. 2018Dr. Lothe Savita A.
12
A real constant must have atleast one digit.
It must have a decimal point.
It could be either positive or negative.
Default sign is positive.
No commas or blanks are allowed within a real
constant.
Eg: +325.02
-32.46
-48.23
13. Rules for constructing real constants in
exponential form:
4th Dec. 2018Dr. Lothe Savita A.
13
• Represented in two parts:
• Part appearing before “e” called mantissa.
• Part following “e” is called as exponent.
• Rules:
• The mantissa part and the exponential part should be separated by
letter e.
• The mantissa may have a (+)or (-) sign.
• Default sign of mantissa part is (+)
• The exponent must have at least one digit which must be a (+)or (-)
integer. Default sign is (+)
• Range is -3.4e38 to 3.4e38
• Eg: +3.2e-5
• 4.1e8
14. Rules for constructing Character
Constants
4th Dec. 2018Dr. Lothe Savita A.
14
A character constant is either a single alphabet, a
single digit or a single special symbol enclosed
within single inverted commas both the inverted
commas should point to the left.
The maximum length of a character constant can be
1 character.
Eg: ’A’
15. C Variables
4th Dec. 2018Dr. Lothe Savita A.
15
A quantity which may vary during program
execution is called Variable.
Variable are names given to locations in the
memory of computer where different constants are
stored.
16. 4th Dec. 2018Dr. Lothe Savita A.
16
• A variable name is any combination of A to Z
alphabets, digits or underscores.
• First character in the variable name must be an
alphabet.
• No commas or blanks are allowed within a variable
name.
• No special symbol other than an underscore can be
used.
• Eg : si_int
• m_hra
• int si, m_hra;
17. C Keywords
4th Dec. 2018Dr. Lothe Savita A.
17
• Called as RESERVED WORDS.
• The keywords cannot be used as variable names.
AUTO DOUBLE IF STATIC
BREAK ELSE INT STRUCT
CASE ENUM LONG SWITCH
CHAR EXTERN NEAR TYPEDEF
CONST FLOAT REGISTER UNION
CONTINUE FAR RETURN UNSIGNED
DEFAULT FOR SHORT VOID
DO GOTO SIGNED WHILE
18. Function Main(1/4)2-18
Contains two parts
Part 1: Declarations
the part of a program that tells the compiler
the names of memory cells in a program
Part 2: Executable statements
program lines that are converted to machine
language instructions and executed by the
computer
4th Dec. 2018Dr. Lothe Savita A.
20. Function Main (3/4)2-20
Examples: int
main(void)
{
printf(“Hello worldn”);
return(0);
}
4th Dec. 2018Dr. Lothe Savita A.
21. Function “Main”(4/4)2-21
int
indicates that the main function returns an integer value
(0) to the operating system when it finishes normal
execution
(void)
indicate that the main function receives no data from
the operating system
4th Dec. 2018Dr. Lothe Savita A.
22. First C program
4th Dec. 2018Dr. Lothe Savita A.
22
#include<stdio.h>
void main()
{
int p,n;
float r,si;
p=1000;
n=3;
r=8.5;
si=p*n*r/100;
printf(“%f”,si);
getch()
}