SlideShare a Scribd company logo
1 of 18
©LPU CSE101 C Programming
CSE101-Lec#3
• Constant
• Variable
• Expression
©LPU CSE101 C Programming
Outline
• In this lecture we will study
– Constant
– Variable
– Expression
©LPU CSE101 C Programming
Tokens
• We have seen that Tokens are broadly classified as:
– Identifiers
– Keywords
– Constants
– Variables
– Strings
– Operators
– Special character
©LPU CSE101 C Programming
Constants
Lion
Spanner
©LPU CSE101 C Programming
Constants
• The entity which do not change throughout
the execution are called constants.
• Types of constants:
– Integer constant
– Character constant
– Floating point constants
– String constants
Name of person remains same through out
the life, example: Amit, Shubnam, etc.
©LPU CSE101 C Programming
• Integer Constants
– When the constant contains only digits without
any decimal part
• Floating Constant
– Constants that contains number with decimal
points
Example : 5;
-987;
Example : 3.14;
309.89
©LPU CSE101 C Programming
• Character constants
– Constants enclosed in single quotes(‘ ’).
– It can be any letter from character set.
• String Constants
– Set of zero or more characters enclosed in double
quotes (eg: “ ” )
– It is represented as sequence of characters within
double quotes.
Example : “This is C programming”
Example : ‘n’, ‘t’ or ‘a’
©LPU CSE101 C Programming
My-Car
In My-Car problem the constant value is 3.14
which is the value of pi and always same.
• pi = 3.14
Therefore:
dist_travelled = 2 * pi * radius.
 pi is a floating point constant.
©LPU CSE101 C Programming
Variables
Animal
Tool
©LPU CSE101 C Programming
Variables
• Variable is an entity which may change.
• Variable is used to hold result and reserve
memory for the data.
datatype variable_name;
The naming of variable is done by following
the same rules of identifier naming.
Eg. What is your hobby?
The answer could be reading, dancing, drawing, etc.
So the answer to such questions may change during the life
time of the person
©LPU CSE101 C Programming
Rules for naming a Variable
1. An variable name is any combination of 1 to 31
alphabets, digits or underscores.
2. The first character in the variable name must be an
alphabet or underscore.
3. No blanks or special symbol other than an
underscore can be used in an variable name.
4. Keywords are not allowed to be used as variables.
©LPU CSE101 C Programming
Variables
In My-Car problem the variable was
• radius and dist_travelled
It can also be named as
• radius_wheel or r1 or
car_wheel_radius
• Distance or d1 or
dist_by_1rotation
©LPU CSE101 C Programming
Variables
Let us build some variables:
For speed of car we need to know
• Distance traveled
• Time taken to travel the distance
Variables to be declared as
• Speed, s1, speed_of_car
• Distance, d1, dist
• Time, t1, time_of_travel
©LPU CSE101 C Programming
See-Saw
• A bit more complex situation see-saw
Variables to be declared as
• Weight_boy, w1, wb
• Distance_boy, d1, db
• Weight_girl, w2, wg
• Distance_girl, d2, dg
• It is to be assessed that at what distance 50Kg girl
should sit in order to balance a boy of 70Kg
sitting 2m away from the center ‘o’
𝑤1 × 𝑑1 = 𝑤2 × 𝑑2
𝑤𝑏 × 𝑑𝑏 = 𝑤𝑔 × 𝑑𝑔
©LPU CSE101 C Programming
Variable Initialization
• Assigning some value to the variable at
time of creation of variable is known as
variable initialization.
datatype variable_name = value;
Example: int radius= 15;
float pi = 3.14;
char grade = ‘A’;
©LPU CSE101 C Programming
Expressions
• Expressions are the statements or the instruction
given to computer to perform some operation.
• Every expression results in some value that can
be stored in a variable.
• Following are few example of expressions in
program:
– Expression to calculate speed of a car.
• Speed=distance/time
– Expression to find similarity of two things.
• c=value1>value2
©LPU CSE101 C Programming
• Expressions in C are basically operators acting on operands.
• An operand is an entity on which operation is to be performed.
• An operator specifies the operation to be applied on operands.
• Expressions are made of one or more operands.
• Statements like :
a = b + c,
++z
300 > (8 * k)
Example: addition of two numbers, 5+8, these numbers will be
operands.
Example: The addition, subtraction, etc will be operators
©LPU CSE101 C Programming
Types of Expressions
• The type of expression depend upon the type of
operator used in the expression.
• It can be:
– Arithmetic operators.
3 + 6 = 9
4 * 2 = 8
– Relational or logical operators.
height_boy>=height_girl
– Increment and decrement operator.
count=count++

More Related Content

Similar to lec3.pptx ppt on orientations computing

C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
Pranoti Doke
 

Similar to lec3.pptx ppt on orientations computing (20)

M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Funa-C.ppt
Funa-C.pptFuna-C.ppt
Funa-C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
C programming basic pdf.ppt
C programming basic pdf.pptC programming basic pdf.ppt
C programming basic pdf.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.pptBasics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of c
Basics of cBasics of c
Basics of c
 
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti DokeC programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 

Recently uploaded

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Recently uploaded (20)

Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 

lec3.pptx ppt on orientations computing

  • 1. ©LPU CSE101 C Programming CSE101-Lec#3 • Constant • Variable • Expression
  • 2. ©LPU CSE101 C Programming Outline • In this lecture we will study – Constant – Variable – Expression
  • 3. ©LPU CSE101 C Programming Tokens • We have seen that Tokens are broadly classified as: – Identifiers – Keywords – Constants – Variables – Strings – Operators – Special character
  • 4. ©LPU CSE101 C Programming Constants Lion Spanner
  • 5. ©LPU CSE101 C Programming Constants • The entity which do not change throughout the execution are called constants. • Types of constants: – Integer constant – Character constant – Floating point constants – String constants Name of person remains same through out the life, example: Amit, Shubnam, etc.
  • 6. ©LPU CSE101 C Programming • Integer Constants – When the constant contains only digits without any decimal part • Floating Constant – Constants that contains number with decimal points Example : 5; -987; Example : 3.14; 309.89
  • 7. ©LPU CSE101 C Programming • Character constants – Constants enclosed in single quotes(‘ ’). – It can be any letter from character set. • String Constants – Set of zero or more characters enclosed in double quotes (eg: “ ” ) – It is represented as sequence of characters within double quotes. Example : “This is C programming” Example : ‘n’, ‘t’ or ‘a’
  • 8. ©LPU CSE101 C Programming My-Car In My-Car problem the constant value is 3.14 which is the value of pi and always same. • pi = 3.14 Therefore: dist_travelled = 2 * pi * radius.  pi is a floating point constant.
  • 9. ©LPU CSE101 C Programming Variables Animal Tool
  • 10. ©LPU CSE101 C Programming Variables • Variable is an entity which may change. • Variable is used to hold result and reserve memory for the data. datatype variable_name; The naming of variable is done by following the same rules of identifier naming. Eg. What is your hobby? The answer could be reading, dancing, drawing, etc. So the answer to such questions may change during the life time of the person
  • 11. ©LPU CSE101 C Programming Rules for naming a Variable 1. An variable name is any combination of 1 to 31 alphabets, digits or underscores. 2. The first character in the variable name must be an alphabet or underscore. 3. No blanks or special symbol other than an underscore can be used in an variable name. 4. Keywords are not allowed to be used as variables.
  • 12. ©LPU CSE101 C Programming Variables In My-Car problem the variable was • radius and dist_travelled It can also be named as • radius_wheel or r1 or car_wheel_radius • Distance or d1 or dist_by_1rotation
  • 13. ©LPU CSE101 C Programming Variables Let us build some variables: For speed of car we need to know • Distance traveled • Time taken to travel the distance Variables to be declared as • Speed, s1, speed_of_car • Distance, d1, dist • Time, t1, time_of_travel
  • 14. ©LPU CSE101 C Programming See-Saw • A bit more complex situation see-saw Variables to be declared as • Weight_boy, w1, wb • Distance_boy, d1, db • Weight_girl, w2, wg • Distance_girl, d2, dg • It is to be assessed that at what distance 50Kg girl should sit in order to balance a boy of 70Kg sitting 2m away from the center ‘o’ 𝑤1 × 𝑑1 = 𝑤2 × 𝑑2 𝑤𝑏 × 𝑑𝑏 = 𝑤𝑔 × 𝑑𝑔
  • 15. ©LPU CSE101 C Programming Variable Initialization • Assigning some value to the variable at time of creation of variable is known as variable initialization. datatype variable_name = value; Example: int radius= 15; float pi = 3.14; char grade = ‘A’;
  • 16. ©LPU CSE101 C Programming Expressions • Expressions are the statements or the instruction given to computer to perform some operation. • Every expression results in some value that can be stored in a variable. • Following are few example of expressions in program: – Expression to calculate speed of a car. • Speed=distance/time – Expression to find similarity of two things. • c=value1>value2
  • 17. ©LPU CSE101 C Programming • Expressions in C are basically operators acting on operands. • An operand is an entity on which operation is to be performed. • An operator specifies the operation to be applied on operands. • Expressions are made of one or more operands. • Statements like : a = b + c, ++z 300 > (8 * k) Example: addition of two numbers, 5+8, these numbers will be operands. Example: The addition, subtraction, etc will be operators
  • 18. ©LPU CSE101 C Programming Types of Expressions • The type of expression depend upon the type of operator used in the expression. • It can be: – Arithmetic operators. 3 + 6 = 9 4 * 2 = 8 – Relational or logical operators. height_boy>=height_girl – Increment and decrement operator. count=count++

Editor's Notes

  1. Variable is data name used for storing a data value
  2. Variable is data name used for storing a data value
  3. During declaration no memory space is allocated to an identifier. Definition of identifier means the declaration of identifier + reservation of space for it in memory
  4. A=b+c….three operands and 2 operators