SlideShare a Scribd company logo
©LPU CSE101 C Programming
©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
• 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
• 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
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
• What are the entities whose values can be
changed called?
• a) Constants
b) Variables
c) Modules
d) Tokens
©LPU CSE101 C Programming
• What are the entities whose values can be
changed called?
• a) Constants
b) Variables
c) Modules
d) Tokens
©LPU CSE101 C Programming
• What are the entities whose values cannot
be changed called?
• a) Constants
b) Variables
c) Modules
d) Tokens
©LPU CSE101 C Programming
• What are the entities whose values cannot
be changed called?
• a) Constants
b) Variables
c) Modules
d) Tokens
©LPU CSE101 C Programming
Which of the following is true for variable names
in C?
A. Variable names cannot start with a digit
B. Variable can be of any length
C. They can contain alphanumeric characters as
well as special characters
D. Reserved Word can be used as variable name
©LPU CSE101 C Programming
Which of the following is true for variable names
in C?
A. Variable names cannot start with a digit
B. Variable can be of any length
C. They can contain alphanumeric characters as
well as special characters
D. Reserved Word can be used as variable name
©LPU CSE101 C Programming
• Which of the following cannot be a variable
name in C?
• A. TRUE
B. friend
C. export
D. volatile
©LPU CSE101 C Programming
• Which of the following cannot be a variable
name in C?
• A. TRUE
B. friend
C. export
D. volatile
©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++
©LPU CSE101 C Programming
• What is the output of this program?
•
• void main()
• {
• int x = 10;
• float x = 10;
• printf("%d", x)
• }
• A. Compilations Error
• B. 10
• C. 10
• D. 10.1
©LPU CSE101 C Programming
• What is the output of this program?
• void main()
• {
• int x = 10;
• float x = 10;
• printf("%d", x)
• }
• A. Compilations Error
• B. 10
• C. 10
• D. 10.1
©LPU CSE101 C Programming
• In this lecture we will study
– Operators
– Types of Operators
©LPU CSE101 C Programming
Operators
• Operator is the symbol which performs some
operations on the operands.
5+5=10 + and = are the operator and
5 and 10 are operands
©LPU CSE101 C Programming
Types of Operators
• Types of operators are:
1. Arithmetic operator
2. Unary operator
3. Relational operator
4. Logical operator
5. Assignment operator
6. Conditional operator
7. Bitwise operator
8. Special operator
©LPU CSE101 C Programming
cse101@lpu.co.in
Next Class: Operators
Types of operators…contd.

More Related Content

Similar to CSE101_Lec 23.pptx

Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
kiran833055
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).ppt
HeshamMohamed855920
 
C programming basic pdf.ppt
C programming basic pdf.pptC programming basic pdf.ppt
C programming basic pdf.ppt
KauserJahan6
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
KrishKumar690406
 
Basics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.pptBasics of C--C Basics------------------.ppt
Basics of C--C Basics------------------.ppt
Ravi Chandra Medisetty
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
kabhinavin
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
MITSINDHAV2
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
ChiranjeevivarmaP
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
SangramNayak23
 
Basics of C
Basics of CBasics of C
Basics of C
pksahoo9
 
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
Dr.Florence Dayana
 
Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2
Dhiviya Rose
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
SeethaDinesh
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
RohanJoshi290109
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
AnshSrivastava48
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
MamataAnilgod
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
KRUNAL RAVAL
 

Similar to CSE101_Lec 23.pptx (20)

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
 
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.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of c
Basics of cBasics of c
Basics of c
 
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
 
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
 
Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2Programming for Problem Solving Unit 2
Programming for Problem Solving Unit 2
 
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
 
C PROGRAMMING LANGUAGE.pptx
 C PROGRAMMING LANGUAGE.pptx C PROGRAMMING LANGUAGE.pptx
C PROGRAMMING LANGUAGE.pptx
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
 

Recently uploaded

Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
AnirbanRoy608946
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
ewymefz
 
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
2023240532
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
ahzuo
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
dwreak4tg
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
u86oixdj
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
oz8q3jxlp
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 

Recently uploaded (20)

Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单一比一原版(NYU毕业证)纽约大学毕业证成绩单
一比一原版(NYU毕业证)纽约大学毕业证成绩单
 
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
 
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
一比一原版(CBU毕业证)卡普顿大学毕业证如何办理
 
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
一比一原版(BCU毕业证书)伯明翰城市大学毕业证如何办理
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
原版制作(swinburne毕业证书)斯威本科技大学毕业证毕业完成信一模一样
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
一比一原版(Deakin毕业证书)迪肯大学毕业证如何办理
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 

CSE101_Lec 23.pptx

  • 1. ©LPU CSE101 C Programming
  • 2. ©LPU CSE101 C Programming Tokens • We have seen that Tokens are broadly classified as: – Identifiers – Keywords – Constants – Variables – Strings – Operators – Special character
  • 3. ©LPU CSE101 C Programming Constants Lion Spanner
  • 4. ©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.
  • 5. ©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’
  • 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 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.
  • 8. ©LPU CSE101 C Programming Variables Animal Tool
  • 9. ©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
  • 10. ©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.
  • 11. ©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
  • 12. ©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
  • 13. ©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 𝑤𝑏 × 𝑑𝑏 = 𝑤𝑔 × 𝑑𝑔
  • 14. ©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’;
  • 15. ©LPU CSE101 C Programming • What are the entities whose values can be changed called? • a) Constants b) Variables c) Modules d) Tokens
  • 16. ©LPU CSE101 C Programming • What are the entities whose values can be changed called? • a) Constants b) Variables c) Modules d) Tokens
  • 17. ©LPU CSE101 C Programming • What are the entities whose values cannot be changed called? • a) Constants b) Variables c) Modules d) Tokens
  • 18. ©LPU CSE101 C Programming • What are the entities whose values cannot be changed called? • a) Constants b) Variables c) Modules d) Tokens
  • 19. ©LPU CSE101 C Programming Which of the following is true for variable names in C? A. Variable names cannot start with a digit B. Variable can be of any length C. They can contain alphanumeric characters as well as special characters D. Reserved Word can be used as variable name
  • 20. ©LPU CSE101 C Programming Which of the following is true for variable names in C? A. Variable names cannot start with a digit B. Variable can be of any length C. They can contain alphanumeric characters as well as special characters D. Reserved Word can be used as variable name
  • 21. ©LPU CSE101 C Programming • Which of the following cannot be a variable name in C? • A. TRUE B. friend C. export D. volatile
  • 22. ©LPU CSE101 C Programming • Which of the following cannot be a variable name in C? • A. TRUE B. friend C. export D. volatile
  • 23. ©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
  • 24. ©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
  • 25. ©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++
  • 26. ©LPU CSE101 C Programming • What is the output of this program? • • void main() • { • int x = 10; • float x = 10; • printf("%d", x) • } • A. Compilations Error • B. 10 • C. 10 • D. 10.1
  • 27. ©LPU CSE101 C Programming • What is the output of this program? • void main() • { • int x = 10; • float x = 10; • printf("%d", x) • } • A. Compilations Error • B. 10 • C. 10 • D. 10.1
  • 28. ©LPU CSE101 C Programming • In this lecture we will study – Operators – Types of Operators
  • 29. ©LPU CSE101 C Programming Operators • Operator is the symbol which performs some operations on the operands. 5+5=10 + and = are the operator and 5 and 10 are operands
  • 30. ©LPU CSE101 C Programming Types of Operators • Types of operators are: 1. Arithmetic operator 2. Unary operator 3. Relational operator 4. Logical operator 5. Assignment operator 6. Conditional operator 7. Bitwise operator 8. Special operator
  • 31. ©LPU CSE101 C Programming cse101@lpu.co.in Next Class: Operators Types of operators…contd.

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