SlideShare a Scribd company logo
1 of 14
LECTURE 5
PROGRAMMING IN C
LANGUAGE
VIDYA CLASES
Asstt. Professor
Department of computer science and IT
EPRESSIXONS
• An expression in programming language c is a combination of
operators,numbers and names that work together to carry out computation.
• Eg. 5+j , (5*j)+6
• Basic operations which are used to create an expression
• Like + Addition ,- Subtraction ,* Multiplication , / Division , % Remainder
TYPES OF EXPRESSION
 There are four types of expressions exist in C:
• Arithmetic expressions
• Relational expressions
• Logical expressions
• Conditional expressions
ARITHMETIC EXPRESSION
 An arithmetic expression is an expression that consists of
operands and arithmetic operators. An arithmetic expression
computes a value of type int, float or double.
 When an expression contains only integral operands, then it
is known as pure integer expression when it contains only
real operands, it is known as pure real expression, and when
it contains both integral and real operands, it is known as
mixed mode expression.
EVALUATION OF ARITHMETIC EXPRESSIONS
THE EXPRESSIONS ARE EVALUATED BY PERFORMING ONE OPERATION AT A TIME. THE PRECEDENCE AND
ASSOCIATIVITY OF OPERATORS DECIDE THE ORDER OF THE EVALUATION OF INDIVIDUAL OPERATIONS
When individual operations are performed, the following cases can be
happened:
•When both the operands are of type integer, then arithmetic
will be performed, and the result of the operation would be an
integer value. For example, 3/2 will yield 1 not 1.5 as the
fractional part is ignored.
•When both the operands are of type float, then arithmetic will be
performed, and the result of the operation would be a real value. For
example, 2.0/2.0 will yield 1.0, not 1.
•If one operand is of type integer and another operand is of type real,
then the mixed arithmetic will be performed. In this case, the first
operand is converted into a real operand, and then arithmetic is performed to
produce the real value. For example, 6/2.0 will yield 3.0 as the first value of 6 is
converted into 6.0 and then arithmetic is performed to produce 3.0
EXAMPLE
Let's understand through an example.
6*2/ (2+1 * 2/3 + 6) + 8 * (8/4)
Evaluation of expression Description of each operation
6*2/( 2+1 * 2/3 +6) +8 * (8/4) An expression is given.
6*2/(2+2/3 + 6) + 8 * (8/4) 2 is multiplied by 1, giving value 2.
6*2/(2+0+6) + 8 * (8/4) 2 is divided by 3, giving value 0.
6*2/ 8+ 8 * (8/4) 2 is added to 6, giving value 8.
6*2/8 + 8 * 2 8 is divided by 4, giving value 2.
12/8 +8 * 2 6 is multiplied by 2, giving value 12.
1 + 8 * 2 12 is divided by 8, giving value 1.
1 + 16 8 is multiplied by 2, giving value 16.
17 1 is added to 16, giving value 17.
RELATIONAL EXPRESSIONS
• A relational expression is an expression used to compare two operands.
• It is a condition which is used to decide whether the action should be taken
or not.
• In relational expressions, a numeric value cannot be compared with the
string value.
• The result of the relational expression can be either zero or non-zero value.
Here, the zero value is equivalent to a false and non-zero value is equivalent
to true.
Relational Expression Description
x%2 = = 0 This condition is used to check whether the x is an even
number or not. The relational expression results in value 1
if x is an even number otherwise results in value 0.
a!=b It is used to check whether a is not equal to b. This
relational expression results in 1 if a is not equal to b
otherwise 0.
a+b = = x+y It is used to check whether the expression "a+b" is equal
to the expression "x+y".
a>=9 It is used to check whether the value of a is greater than or
equal to 9.
1.#include <stdio.h>
2. int main()
3.{
4.
5. int x=4;
6. if(x%2==0)
7. {
8. printf("The number x is even");
9. }
10. else
11. printf("The number x is not even");
12. return 0;
LOGICAL EXPRESSIONS
A LOGICAL EXPRESSION IS AN EXPRESSION THAT COMPUTES EITHER A ZERO OR NON-ZERO VALUE.
IT IS A COMPLEX TEST CONDITION TO TAKE A DECISION.
Logical Expressions Description
( x > 4 ) && ( x < 6 ) It is a test condition to check whether the x is greater than 4
and x is less than 6. The result of the condition is true only
when both the conditions are true.
x > 10 || y <11 It is a test condition used to check whether x is greater than 10
or y is less than 11. The result of the test condition is true if
either of the conditions holds true value.
! ( x > 10 ) && ( y = = 2 ) It is a test condition used to check whether x is not greater than
10 and y is equal to 2. The result of the condition is true if both
the conditions are true.
1.#include <stdio.h>
2.int main()
3.{
4. int x = 4;
5. int y = 10;
6. if ( (x <10) && (y>5))
7. {
8. printf("Condition is true");
9. }
10. else
11. printf("Condition is false");
12. return 0;
13.}
CONDITIONAL EXPRESSIONS
• A conditional expression is an expression that returns 1 if the condition
is true otherwise 0.
• A conditional operator is also known as a ternary operator.
The Syntax of Conditional operator
Suppose exp1, exp2 and exp3 are three expressions.
exp1 ? exp2 : exp3
The above expression is a conditional expression which is evaluated on
the basis of the value of the exp1 expression. If the
condition of the expression exp1 holds true, then the final conditional
expression is represented by exp2 otherwise represented by exp3.
1.#include<stdio.h>
2.#include<string.h>
3.int main()
4.{
5. int age = 25;
6. char status;
7. status = (age>22) ? 'M': 'U';
8. if(status == 'M')
9. printf("Married");
10. else
11. printf("Unmarried");
12. return 0;
13. }
OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C
Operator precedence:
It dictates the order of evaluation of operators in an expression.
Associativity:
It defines the order in which operators of the same precedence are evaluated in an expression.
Associativity can be either from left to right or right to left.
Consider the following example:
24 + 5 * 4
Here we have two operators + and *, Which operation do you think will be evaluated first, addition
or multiplication?
If the addition is applied first then answer will be
116 And if the multiplication is applied first answer will be 44
,
we can conclude that the * operator is above the + operator, so the * operator has higher precedence
than the + operator, therefore in the expression 24+5*4, subexpression 5*4 will be evaluated first
Thank you

More Related Content

Similar to lecture5 bca 1 year.pptx

Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderMoni Adhikary
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptxMAHAMASADIK
 
Function notation by sadiq
Function notation by sadiqFunction notation by sadiq
Function notation by sadiqSadiq Hussain
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)jahanullah
 
python operators.pptx
python operators.pptxpython operators.pptx
python operators.pptxirsatanoli
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentalsumar78600
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperatorteach4uin
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 

Similar to lecture5 bca 1 year.pptx (20)

Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Simple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladderSimple if else statement,nesting of if else statement &amp; else if ladder
Simple if else statement,nesting of if else statement &amp; else if ladder
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
 
Function notation by sadiq
Function notation by sadiqFunction notation by sadiq
Function notation by sadiq
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
C tutorial
C tutorialC tutorial
C tutorial
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Chap 4 c++
Chap 4 c++Chap 4 c++
Chap 4 c++
 
python operators.pptx
python operators.pptxpython operators.pptx
python operators.pptx
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Marh algebra lesson
Marh algebra lessonMarh algebra lesson
Marh algebra lesson
 
C language assignment help
C language assignment helpC language assignment help
C language assignment help
 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
Python second ppt
Python second pptPython second ppt
Python second ppt
 
Php
PhpPhp
Php
 
How to Program
How to ProgramHow to Program
How to Program
 

More from classall

E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.pptclassall
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBclassall
 
operat in vb .pptx
operat in vb .pptxoperat in vb .pptx
operat in vb .pptxclassall
 
Tally_Tutor_1.ppt
Tally_Tutor_1.pptTally_Tutor_1.ppt
Tally_Tutor_1.pptclassall
 
networking
networking networking
networking classall
 
introduction to visual basic PPT.pptx
introduction to visual basic PPT.pptxintroduction to visual basic PPT.pptx
introduction to visual basic PPT.pptxclassall
 
introduction to e-commerce.pptx
introduction to e-commerce.pptxintroduction to e-commerce.pptx
introduction to e-commerce.pptxclassall
 
E-Rdiagram.ppt
E-Rdiagram.pptE-Rdiagram.ppt
E-Rdiagram.pptclassall
 
EDI presentation.pptx
EDI presentation.pptxEDI presentation.pptx
EDI presentation.pptxclassall
 
control structure in visual basic
control structure in visual basic control structure in visual basic
control structure in visual basic classall
 
b,Sc it data structure.ppt
b,Sc it data structure.pptb,Sc it data structure.ppt
b,Sc it data structure.pptclassall
 
SAVE WATER SAVE LIFE
SAVE WATER SAVE LIFESAVE WATER SAVE LIFE
SAVE WATER SAVE LIFEclassall
 
MULTIMEDIA
MULTIMEDIAMULTIMEDIA
MULTIMEDIAclassall
 
GEETA2.pptx
GEETA2.pptxGEETA2.pptx
GEETA2.pptxclassall
 
GEETA1.pptx
GEETA1.pptxGEETA1.pptx
GEETA1.pptxclassall
 
GEETA.pptx
GEETA.pptxGEETA.pptx
GEETA.pptxclassall
 
राष्ट्रीय एकता 13.3.18.ppt
राष्ट्रीय एकता 13.3.18.pptराष्ट्रीय एकता 13.3.18.ppt
राष्ट्रीय एकता 13.3.18.pptclassall
 
b,Sc it data structure.pptx
b,Sc it data structure.pptxb,Sc it data structure.pptx
b,Sc it data structure.pptxclassall
 

More from classall (20)

E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
CONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VBCONTROL STRUCTURE IN VB
CONTROL STRUCTURE IN VB
 
operat in vb .pptx
operat in vb .pptxoperat in vb .pptx
operat in vb .pptx
 
Tally_Tutor_1.ppt
Tally_Tutor_1.pptTally_Tutor_1.ppt
Tally_Tutor_1.ppt
 
networking
networking networking
networking
 
introduction to visual basic PPT.pptx
introduction to visual basic PPT.pptxintroduction to visual basic PPT.pptx
introduction to visual basic PPT.pptx
 
introduction to e-commerce.pptx
introduction to e-commerce.pptxintroduction to e-commerce.pptx
introduction to e-commerce.pptx
 
E-Rdiagram.ppt
E-Rdiagram.pptE-Rdiagram.ppt
E-Rdiagram.ppt
 
EDI presentation.pptx
EDI presentation.pptxEDI presentation.pptx
EDI presentation.pptx
 
control structure in visual basic
control structure in visual basic control structure in visual basic
control structure in visual basic
 
b,Sc it data structure.ppt
b,Sc it data structure.pptb,Sc it data structure.ppt
b,Sc it data structure.ppt
 
SAVE WATER SAVE LIFE
SAVE WATER SAVE LIFESAVE WATER SAVE LIFE
SAVE WATER SAVE LIFE
 
MS OFFICE
MS OFFICEMS OFFICE
MS OFFICE
 
MULTIMEDIA
MULTIMEDIAMULTIMEDIA
MULTIMEDIA
 
GEETA2.pptx
GEETA2.pptxGEETA2.pptx
GEETA2.pptx
 
GEETA1.pptx
GEETA1.pptxGEETA1.pptx
GEETA1.pptx
 
GEETA.pptx
GEETA.pptxGEETA.pptx
GEETA.pptx
 
राष्ट्रीय एकता 13.3.18.ppt
राष्ट्रीय एकता 13.3.18.pptराष्ट्रीय एकता 13.3.18.ppt
राष्ट्रीय एकता 13.3.18.ppt
 
mmu.pptx
mmu.pptxmmu.pptx
mmu.pptx
 
b,Sc it data structure.pptx
b,Sc it data structure.pptxb,Sc it data structure.pptx
b,Sc it data structure.pptx
 

Recently uploaded

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 

lecture5 bca 1 year.pptx

  • 1. LECTURE 5 PROGRAMMING IN C LANGUAGE VIDYA CLASES Asstt. Professor Department of computer science and IT
  • 2. EPRESSIXONS • An expression in programming language c is a combination of operators,numbers and names that work together to carry out computation. • Eg. 5+j , (5*j)+6 • Basic operations which are used to create an expression • Like + Addition ,- Subtraction ,* Multiplication , / Division , % Remainder
  • 3. TYPES OF EXPRESSION  There are four types of expressions exist in C: • Arithmetic expressions • Relational expressions • Logical expressions • Conditional expressions
  • 4. ARITHMETIC EXPRESSION  An arithmetic expression is an expression that consists of operands and arithmetic operators. An arithmetic expression computes a value of type int, float or double.  When an expression contains only integral operands, then it is known as pure integer expression when it contains only real operands, it is known as pure real expression, and when it contains both integral and real operands, it is known as mixed mode expression.
  • 5. EVALUATION OF ARITHMETIC EXPRESSIONS THE EXPRESSIONS ARE EVALUATED BY PERFORMING ONE OPERATION AT A TIME. THE PRECEDENCE AND ASSOCIATIVITY OF OPERATORS DECIDE THE ORDER OF THE EVALUATION OF INDIVIDUAL OPERATIONS When individual operations are performed, the following cases can be happened: •When both the operands are of type integer, then arithmetic will be performed, and the result of the operation would be an integer value. For example, 3/2 will yield 1 not 1.5 as the fractional part is ignored. •When both the operands are of type float, then arithmetic will be performed, and the result of the operation would be a real value. For example, 2.0/2.0 will yield 1.0, not 1. •If one operand is of type integer and another operand is of type real, then the mixed arithmetic will be performed. In this case, the first operand is converted into a real operand, and then arithmetic is performed to produce the real value. For example, 6/2.0 will yield 3.0 as the first value of 6 is converted into 6.0 and then arithmetic is performed to produce 3.0
  • 6. EXAMPLE Let's understand through an example. 6*2/ (2+1 * 2/3 + 6) + 8 * (8/4) Evaluation of expression Description of each operation 6*2/( 2+1 * 2/3 +6) +8 * (8/4) An expression is given. 6*2/(2+2/3 + 6) + 8 * (8/4) 2 is multiplied by 1, giving value 2. 6*2/(2+0+6) + 8 * (8/4) 2 is divided by 3, giving value 0. 6*2/ 8+ 8 * (8/4) 2 is added to 6, giving value 8. 6*2/8 + 8 * 2 8 is divided by 4, giving value 2. 12/8 +8 * 2 6 is multiplied by 2, giving value 12. 1 + 8 * 2 12 is divided by 8, giving value 1. 1 + 16 8 is multiplied by 2, giving value 16. 17 1 is added to 16, giving value 17.
  • 7. RELATIONAL EXPRESSIONS • A relational expression is an expression used to compare two operands. • It is a condition which is used to decide whether the action should be taken or not. • In relational expressions, a numeric value cannot be compared with the string value. • The result of the relational expression can be either zero or non-zero value. Here, the zero value is equivalent to a false and non-zero value is equivalent to true. Relational Expression Description x%2 = = 0 This condition is used to check whether the x is an even number or not. The relational expression results in value 1 if x is an even number otherwise results in value 0. a!=b It is used to check whether a is not equal to b. This relational expression results in 1 if a is not equal to b otherwise 0. a+b = = x+y It is used to check whether the expression "a+b" is equal to the expression "x+y". a>=9 It is used to check whether the value of a is greater than or equal to 9.
  • 8. 1.#include <stdio.h> 2. int main() 3.{ 4. 5. int x=4; 6. if(x%2==0) 7. { 8. printf("The number x is even"); 9. } 10. else 11. printf("The number x is not even"); 12. return 0;
  • 9. LOGICAL EXPRESSIONS A LOGICAL EXPRESSION IS AN EXPRESSION THAT COMPUTES EITHER A ZERO OR NON-ZERO VALUE. IT IS A COMPLEX TEST CONDITION TO TAKE A DECISION. Logical Expressions Description ( x > 4 ) && ( x < 6 ) It is a test condition to check whether the x is greater than 4 and x is less than 6. The result of the condition is true only when both the conditions are true. x > 10 || y <11 It is a test condition used to check whether x is greater than 10 or y is less than 11. The result of the test condition is true if either of the conditions holds true value. ! ( x > 10 ) && ( y = = 2 ) It is a test condition used to check whether x is not greater than 10 and y is equal to 2. The result of the condition is true if both the conditions are true.
  • 10. 1.#include <stdio.h> 2.int main() 3.{ 4. int x = 4; 5. int y = 10; 6. if ( (x <10) && (y>5)) 7. { 8. printf("Condition is true"); 9. } 10. else 11. printf("Condition is false"); 12. return 0; 13.}
  • 11. CONDITIONAL EXPRESSIONS • A conditional expression is an expression that returns 1 if the condition is true otherwise 0. • A conditional operator is also known as a ternary operator. The Syntax of Conditional operator Suppose exp1, exp2 and exp3 are three expressions. exp1 ? exp2 : exp3 The above expression is a conditional expression which is evaluated on the basis of the value of the exp1 expression. If the condition of the expression exp1 holds true, then the final conditional expression is represented by exp2 otherwise represented by exp3.
  • 12. 1.#include<stdio.h> 2.#include<string.h> 3.int main() 4.{ 5. int age = 25; 6. char status; 7. status = (age>22) ? 'M': 'U'; 8. if(status == 'M') 9. printf("Married"); 10. else 11. printf("Unmarried"); 12. return 0; 13. }
  • 13. OPERATOR PRECEDENCE AND ASSOCIATIVITY IN C Operator precedence: It dictates the order of evaluation of operators in an expression. Associativity: It defines the order in which operators of the same precedence are evaluated in an expression. Associativity can be either from left to right or right to left. Consider the following example: 24 + 5 * 4 Here we have two operators + and *, Which operation do you think will be evaluated first, addition or multiplication? If the addition is applied first then answer will be 116 And if the multiplication is applied first answer will be 44 , we can conclude that the * operator is above the + operator, so the * operator has higher precedence than the + operator, therefore in the expression 24+5*4, subexpression 5*4 will be evaluated first