C - PowerPoint PPT Presentation

About This Presentation
Title:

C

Description:

char letter = a'; cout int(letter); // What is displayed? int x=98; cout char(x); //What is displayed? 97. b. Character Typecasting. char letter='a' ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 25
Provided by: Ali4152
Learn more at: https://www.cse.unr.edu
Category:
Tags: letter

less

Transcript and Presenter's Notes

Title: C


1
C
  • Typecasting. Math Library Functions.

2
Operator / Operands
  • A x y

3
Typecasting
  • What is the integral expression?
  • What is a decimal expression?
  • What is mixed expression?
  • What will be the result of those expression?

4
Typecasting
  • What is typecasting?
  • What are the two types of typecasting?
  • Examples

5
Implicit Typecasting
  • 3.4 / 2 3.4 / 2.0 1.7

6
Explicit Typecasting
  • int x3, y2
  • double z
  • z x/y //integer division,
    z1.0
  • z double(x)/y // z1.5

What is the datatype of x after this operation?
7
Explicit Typecasting
  • double(x)
  • is equivalent to
  • (double)x
  • is equivalent to
  • static_castltdoublegtx

8
  • int number
  • cout ltlt Enter a number //User enters 10
  • cin gtgt number
  • What is stored in variable number?

10
9
  • int number
  • cout ltlt Enter a number//User enters 10.3
  • cin gtgt number
  • What is stored in variable number?

10
10
  • float number
  • cout ltlt Enter a number //User enters 10.3
  • cin gtgt number
  • What is stored in variable number?

10.3
11
  • float number
  • cout ltlt Enter a number //User enters 10
  • cin gtgt number
  • What is stored in variable number?

10.0
12
  • int num13
  • int num25
  • int product
  •  
  • product num1 num2
  • What is stored in variable product?

15
13
  • float num13.1
  • int num25
  • int product
  •  
  • product num1 num2
  • What is stored in variable product?
  •  

15
14
  • float num13.1
  • int num25
  • float product
  •  
  • product num1 num2
  • What is stored in variable product?
  •  

15.5
15
  •  
  • int num13
  • int num25
  • float product
  •  
  • product num1 num2
  • What is stored in variable product?
  •  

15.0
16
Integer Division ( / )
  • int/int ? int
  •  
  • 10/3
  • 30/5
  • 5/6
  • 9/8
  • 22/5

17
Mod Operator ( )
  • int int int
  •  
  • 103
  • 305
  • 56
  • 98
  • 225

18
  • int num1 13
  • int num2 4
  • int quotient
  •  
  • quotient num1 /num2
  • What is stored in variable quotient?
  •  
  •  

3
19
  • int num1 13
  • int num2 4
  • float quotient
  •  
  • quotient num1 /num2
  • What is stored in variable quotient?
  •  
  •  

3.0
20
  • int num113
  • int num24
  • float quotient
  • quotient float(num1) /num2
  • What is stored in variable quotient?
  • What is stored in variable num1?
  •  

3.25 13
21
  • int num113
  • int num24
  • float quotient
  • quotient float(num1/num2)
  • What is stored in variable quotient?
  •  

3.0
22
Character Typecasting
  • char letter a
  • coutltlt int(letter) // What is displayed?
  • int x98
  • coutltltchar(x) //What is displayed?

97
b
23
Character Typecasting
  • char letter'a'
  • coutltlt int(letter) ltlt endl
  • letter letter 1
  • coutltlt letter ltlt endl
  • coutltlt letter 1 ltlt endl
  • coutltlt char (letter1) ltlt endl
  • coutltlt int(letter) ltlt endl

97
b
99
c
98
24
  • Find an average of three numbers
  • int x, y, z
  • float average
  • average(xyz)/3
  • average(float(x)yz)/3.0
  • average(xyz)/3.0
Write a Comment
User Comments (0)
About PowerShow.com