SlideShare a Scribd company logo
Objectives
• Be able to explain to others what a data type is
• Be able to use basic data types in C programs
• Be able to see the inaccuracies and limitations introduced
by machine representations of numbers
CoxSimple Data Types2
What do you see?
CoxSimple Data Types3
What do you see?
CoxSimple Data Types4
Last one
CoxSimple Data Types5
CoxSimple Data Types6
Everything is Just a Bunch of Bits
• Bits can represent many different things
• Depends on interpretation
• You and your program must keep track of what kind of data
is at each location in the computer’s memory
• E.g., program data types
CoxSimple Data Types7
Big Picture
• Processor works with finite-sized data
• All data implemented as a sequence of bits
• Bit = 0 or 1
• Represents the level of an electrical charge
• Byte = 8 bits
• Word = largest data size handled by processor
• 32 bits on most older computers
• 64 bits on most new computers
CoxSimple Data Types8
Data types in C
•Only really four basic types:
• char
• int (short, long, long long, unsigned)
• float
• double
•Size of these types on
•CLEAR machines:
•Sizes of these types
•vary from one machine
•to another!
Type Size (bytes)
char 1
int 4
short 2
long 8
long long 8
float 4
double 8
CoxSimple Data Types9
Characters (char)
• Roman alphabet, punctuation, digits, and other symbols:
• Encoded within one byte (256 possible symbols)
• ASCII encoding (man ascii for details)
• In C:
char a_char = ’a’;
char newline_char = ’n’;
char tab_char = ’t’;
char backslash_char = ’’;
CoxSimple Data Types10
ASCII
From “man ascii”:
| 0 NUL| 1 SOH| 2 STX| 3 ETX| 4 EOT| 5 ENQ| 6 ACK| 7 BEL|
| 8 BS | 9 HT | 10 NL | 11 VT | 12 NP | 13 CR | 14 SO | 15 SI |
| 16 DLE| 17 DC1| 18 DC2| 19 DC3| 20 DC4| 21 NAK| 22 SYN| 23 ETB|
| 24 CAN| 25 EM | 26 SUB| 27 ESC| 28 FS | 29 GS | 30 RS | 31 US |
| 32 SP | 33 ! | 34 " | 35 # | 36 $ | 37 % | 38 & | 39 ' |
| 40 ( | 41 ) | 42 * | 43 + | 44 , | 45 - | 46 . | 47 / |
| 48 0 | 49 1 | 50 2 | 51 3 | 52 4 | 53 5 | 54 6 | 55 7 |
| 56 8 | 57 9 | 58 : | 59 ; | 60 < | 61 = | 62 > | 63 ? |
| 64 @ | 65 A | 66 B | 67 C | 68 D | 69 E | 70 F | 71 G |
| 72 H | 73 I | 74 J | 75 K | 76 L | 77 M | 78 N | 79 O |
| 80 P | 81 Q | 82 R | 83 S | 84 T | 85 U | 86 V | 87 W |
| 88 X | 89 Y | 90 Z | 91 [ | 92  | 93 ] | 94 ^ | 95 _ |
| 96 ` | 97 a | 98 b | 99 c |100 d |101 e |102 f |103 g |
|104 h |105 i |106 j |107 k |108 l |109 m |110 n |111 o |
|112 p |113 q |114 r |115 s |116 t |117 u |118 v |119 w |
|120 x |121 y |122 z |123 { |124 | |125 } |126 ~ |127 DEL|
Special
control
characters
CoxSimple Data Types11
Characters are just numbers
•What does this function do?
Char
fun(char c)
{
char new_c;
if ((c >= ’A’) && (c <= ’Z’))
new_c = c - ’A’ + ’a’;
else
new_c = c;
return (new_c);
}
return type
procedure
name
argument type
and name
local variable
type and name
Math on
characters!
comparisons
with characters!
CoxSimple Data Types12
FP vs. Integer Results
int i = 20 / 3;
float f = 20.0 / 3.0;
True mathematical answer: 20  3 = 6 2/3
i = ?
f = ?
6
6.666667
Integer division ignores remainder
FP arithmetic rounds result
CoxSimple Data Types13
Integer Representations
Base 2 Base 16 Unsigned 2’s Comp.
0000 0 0 0
0001 1 1 1
0010 2 2 2
0011 3 3 3
0100 4 4 4
0101 5 5 5
0110 6 6 6
0111 7 7 7
1000 8 8 -8
1001 9 9 -7
1010 A 10 -6
1011 B 11 -5
1100 C 12 -4
1101 D 13 -3
1110 E 14 -2
1111 F 15 -1
0000 0001
0010
0011
0100
0101
0110
011110001001
1011
1100
1101
1010
1110
1111
0
1
2
3
4
5
6
789
A
D
C
B
E
F
0 1
2
3
4
5
6
789
10
11
12
13
14
15
0 1
-8
3
4
5
6
7
2
-7
-6
-5
-4
-3
-2
-1
Why one more negative than positive?
CoxSimple Data Types14
Integer Representations
Math for n bits:
Define




1
0
2)(2
n
i
i
i
xxUB







2
0
1
1
22)(2
n
i
i
i
n
n
xxxTB

01 xxx n 


sign bit
0=non-negative
1=negative
Base 2 Base 16 Unsigned 2’s Comp.
0000 0 0 0
0001 1 1 1
0010 2 2 2
0011 3 3 3
0100 4 4 4
0101 5 5 5
0110 6 6 6
0111 7 7 7
1000 8 8 -8
1001 9 9 -7
1010 A 10 -6
1011 B 11 -5
1100 C 12 -4
1101 D 13 -3
1110 E 14 -2
1111 F 15 -1
15
Memory Layout of Records
initials
(2 bytes)
married
(1 byte)
ss_number
(4 bytes)
• Fields are stored adjacently in memory.
• Memory is allocated for records based on
the order the fields are created.
• Variables are aligned for easy reference.
initials
(2 bytes)
ss_number
(4 bytes)
married
(1 byte)
Optimized for space Optimized for memory alignment
4 bytes / 32 bits 4 bytes / 32 bits
Data types in C programming

More Related Content

What's hot

BC Math 10 Systems Practice Test
BC Math 10 Systems Practice TestBC Math 10 Systems Practice Test
BC Math 10 Systems Practice Test
Hun Kim
 
Jeopardy chapter 6
Jeopardy chapter 6Jeopardy chapter 6
Jeopardy chapter 6
samanthanewgas
 
PPT On Puzzle Patterns For class 9
PPT On Puzzle Patterns For class 9 PPT On Puzzle Patterns For class 9
PPT On Puzzle Patterns For class 9
Raksha Sharma
 
BC Math 10 Exponents Practice Test
BC Math 10 Exponents Practice TestBC Math 10 Exponents Practice Test
BC Math 10 Exponents Practice Test
Hun Kim
 
actel fpga problems
actel fpga problemsactel fpga problems
actel fpga problems
Anish Gupta
 
2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translations2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translations
dswanstromecasd
 
Gambar Grafik Suatu fungsi
Gambar Grafik Suatu fungsiGambar Grafik Suatu fungsi
Gambar Grafik Suatu fungsi
Sriwijaya University
 
Math review for 4th period exam
Math review for 4th period examMath review for 4th period exam
Math review for 4th period exam
Dulce Garza
 
Math review for 4th period exam
Math review for 4th period examMath review for 4th period exam
Math review for 4th period exam
Dulce Garza
 
Solucion compendio 4
Solucion compendio 4Solucion compendio 4
Solucion compendio 4
cannia
 
xilinx fpga problems
xilinx fpga problemsxilinx fpga problems
xilinx fpga problems
Anish Gupta
 
TechMathII - Chapter1 Review Jeopardy
TechMathII - Chapter1 Review JeopardyTechMathII - Chapter1 Review Jeopardy
TechMathII - Chapter1 Review Jeopardy
lmrhodes
 

What's hot (12)

BC Math 10 Systems Practice Test
BC Math 10 Systems Practice TestBC Math 10 Systems Practice Test
BC Math 10 Systems Practice Test
 
Jeopardy chapter 6
Jeopardy chapter 6Jeopardy chapter 6
Jeopardy chapter 6
 
PPT On Puzzle Patterns For class 9
PPT On Puzzle Patterns For class 9 PPT On Puzzle Patterns For class 9
PPT On Puzzle Patterns For class 9
 
BC Math 10 Exponents Practice Test
BC Math 10 Exponents Practice TestBC Math 10 Exponents Practice Test
BC Math 10 Exponents Practice Test
 
actel fpga problems
actel fpga problemsactel fpga problems
actel fpga problems
 
2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translations2 5 2-6 absolute value graphs and translations
2 5 2-6 absolute value graphs and translations
 
Gambar Grafik Suatu fungsi
Gambar Grafik Suatu fungsiGambar Grafik Suatu fungsi
Gambar Grafik Suatu fungsi
 
Math review for 4th period exam
Math review for 4th period examMath review for 4th period exam
Math review for 4th period exam
 
Math review for 4th period exam
Math review for 4th period examMath review for 4th period exam
Math review for 4th period exam
 
Solucion compendio 4
Solucion compendio 4Solucion compendio 4
Solucion compendio 4
 
xilinx fpga problems
xilinx fpga problemsxilinx fpga problems
xilinx fpga problems
 
TechMathII - Chapter1 Review Jeopardy
TechMathII - Chapter1 Review JeopardyTechMathII - Chapter1 Review Jeopardy
TechMathII - Chapter1 Review Jeopardy
 

Similar to Data types in C programming

Kaizen cso002 l1
Kaizen cso002 l1Kaizen cso002 l1
Kaizen cso002 l1
asslang
 
8th Semester (June; July-2015) Computer Science and Information Science Engin...
8th Semester (June; July-2015) Computer Science and Information Science Engin...8th Semester (June; July-2015) Computer Science and Information Science Engin...
8th Semester (June; July-2015) Computer Science and Information Science Engin...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
microprocessors
microprocessorsmicroprocessors
microprocessors
Hossam Zein
 
Digital electronics-Introduction.pptx
Digital electronics-Introduction.pptxDigital electronics-Introduction.pptx
Digital electronics-Introduction.pptx
Subrata Maiti
 
Creating a Custom Serialization Format (Gophercon 2017)
Creating a Custom Serialization Format (Gophercon 2017)Creating a Custom Serialization Format (Gophercon 2017)
Creating a Custom Serialization Format (Gophercon 2017)
Scott Mansfield
 
Understand data representation on CPU 1
Understand data representation on CPU 1Understand data representation on CPU 1
Understand data representation on CPU 1
Brenda Debra
 
dld 01-introduction
dld 01-introductiondld 01-introduction
dld 01-introduction
United International University
 
Digital Electronics Notes.pdf
Digital Electronics Notes.pdfDigital Electronics Notes.pdf
Digital Electronics Notes.pdf
4NM21IS132SAISHARATH
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
cookie1969
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
Connor McDonald
 
5th Semester (June-2016) Computer Science and Information Science Engineering...
5th Semester (June-2016) Computer Science and Information Science Engineering...5th Semester (June-2016) Computer Science and Information Science Engineering...
5th Semester (June-2016) Computer Science and Information Science Engineering...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Finite word length effects
Finite word length effectsFinite word length effects
Finite word length effects
PeriyanayagiS
 
8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...
8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...
8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
8th semester Computer Science and Information Science Engg (2013 December) Qu...
8th semester Computer Science and Information Science Engg (2013 December) Qu...8th semester Computer Science and Information Science Engg (2013 December) Qu...
8th semester Computer Science and Information Science Engg (2013 December) Qu...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Mat lab
Mat labMat lab
Dsd previous year university questions
Dsd previous year university questionsDsd previous year university questions
Dsd previous year university questions
thiyagu0484
 
7th Semester (June; July-2014) Electronics and Communication Engineering Ques...
7th Semester (June; July-2014) Electronics and Communication Engineering Ques...7th Semester (June; July-2014) Electronics and Communication Engineering Ques...
7th Semester (June; July-2014) Electronics and Communication Engineering Ques...
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
info382133
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applications
Connor McDonald
 

Similar to Data types in C programming (20)

Kaizen cso002 l1
Kaizen cso002 l1Kaizen cso002 l1
Kaizen cso002 l1
 
8th Semester (June; July-2015) Computer Science and Information Science Engin...
8th Semester (June; July-2015) Computer Science and Information Science Engin...8th Semester (June; July-2015) Computer Science and Information Science Engin...
8th Semester (June; July-2015) Computer Science and Information Science Engin...
 
microprocessors
microprocessorsmicroprocessors
microprocessors
 
Digital electronics-Introduction.pptx
Digital electronics-Introduction.pptxDigital electronics-Introduction.pptx
Digital electronics-Introduction.pptx
 
Creating a Custom Serialization Format (Gophercon 2017)
Creating a Custom Serialization Format (Gophercon 2017)Creating a Custom Serialization Format (Gophercon 2017)
Creating a Custom Serialization Format (Gophercon 2017)
 
Understand data representation on CPU 1
Understand data representation on CPU 1Understand data representation on CPU 1
Understand data representation on CPU 1
 
dld 01-introduction
dld 01-introductiondld 01-introduction
dld 01-introduction
 
Digital Electronics Notes.pdf
Digital Electronics Notes.pdfDigital Electronics Notes.pdf
Digital Electronics Notes.pdf
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
 
5th Semester (June-2016) Computer Science and Information Science Engineering...
5th Semester (June-2016) Computer Science and Information Science Engineering...5th Semester (June-2016) Computer Science and Information Science Engineering...
5th Semester (June-2016) Computer Science and Information Science Engineering...
 
Finite word length effects
Finite word length effectsFinite word length effects
Finite word length effects
 
8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...
8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...
8th Semeste Electronics and Communication Engineering (June-2016) Question Pa...
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
8th semester Computer Science and Information Science Engg (2013 December) Qu...
8th semester Computer Science and Information Science Engg (2013 December) Qu...8th semester Computer Science and Information Science Engg (2013 December) Qu...
8th semester Computer Science and Information Science Engg (2013 December) Qu...
 
Mat lab
Mat labMat lab
Mat lab
 
Dsd previous year university questions
Dsd previous year university questionsDsd previous year university questions
Dsd previous year university questions
 
7th Semester (June; July-2014) Electronics and Communication Engineering Ques...
7th Semester (June; July-2014) Electronics and Communication Engineering Ques...7th Semester (June; July-2014) Electronics and Communication Engineering Ques...
7th Semester (June; July-2014) Electronics and Communication Engineering Ques...
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
 
SQL techniques for faster applications
SQL techniques for faster applicationsSQL techniques for faster applications
SQL techniques for faster applications
 

More from Osama Ghandour Geris

functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
Osama Ghandour Geris
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Osama Ghandour Geris
 
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansourPython cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Osama Ghandour Geris
 
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandourPython cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10
Osama Ghandour Geris
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10
Osama Ghandour Geris
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Python week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandourPython week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Programming intro variables constants - arithmetic and assignment operators
Programming intro variables   constants - arithmetic and assignment operatorsProgramming intro variables   constants - arithmetic and assignment operators
Programming intro variables constants - arithmetic and assignment operators
Osama Ghandour Geris
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osama
Osama Ghandour Geris
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
Osama Ghandour Geris
 
6 css week12 2020 2021 for g10
6 css week12 2020 2021 for g106 css week12 2020 2021 for g10
6 css week12 2020 2021 for g10
Osama Ghandour Geris
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandour
Osama Ghandour Geris
 
Cooding history
Cooding history Cooding history
Cooding history
Osama Ghandour Geris
 
Computer networks--network
Computer networks--networkComputer networks--network
Computer networks--network
Osama Ghandour Geris
 
How to print a sketch up drawing in 3d
How to print a sketch up drawing  in 3dHow to print a sketch up drawing  in 3d
How to print a sketch up drawing in 3d
Osama Ghandour Geris
 
Google sketch up-tutorial
Google sketch up-tutorialGoogle sketch up-tutorial
Google sketch up-tutorial
Osama Ghandour Geris
 
7 types of presentation styles on line
7 types of presentation styles on line7 types of presentation styles on line
7 types of presentation styles on line
Osama Ghandour Geris
 
Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020
Osama Ghandour Geris
 
Php introduction
Php introductionPhp introduction
Php introduction
Osama Ghandour Geris
 

More from Osama Ghandour Geris (20)

functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
 
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.pptPython week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
 
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansourPython cs.1.12 week 10  2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
 
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandourPython cs.1.12 week 9 10  2020-2021 covid 19 for g10 by eng.osama ghandour
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
 
Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10Python week 7 8 2019-2020 for grade 10
Python week 7 8 2019-2020 for grade 10
 
Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10 Python week 6 2019 2020 for grade 10
Python week 6 2019 2020 for grade 10
 
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandourPython week 5 2019 2020 for g10 by eng.osama ghandour
Python week 5 2019 2020 for g10 by eng.osama ghandour
 
Python week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandourPython week 4 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandour
 
Programming intro variables constants - arithmetic and assignment operators
Programming intro variables   constants - arithmetic and assignment operatorsProgramming intro variables   constants - arithmetic and assignment operators
Programming intro variables constants - arithmetic and assignment operators
 
Mobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osamaMobile appliaction w android week 1 by osama
Mobile appliaction w android week 1 by osama
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
 
6 css week12 2020 2021 for g10
6 css week12 2020 2021 for g106 css week12 2020 2021 for g10
6 css week12 2020 2021 for g10
 
Css week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandourCss week11 2020 2021 for g10 by eng.osama ghandour
Css week11 2020 2021 for g10 by eng.osama ghandour
 
Cooding history
Cooding history Cooding history
Cooding history
 
Computer networks--network
Computer networks--networkComputer networks--network
Computer networks--network
 
How to print a sketch up drawing in 3d
How to print a sketch up drawing  in 3dHow to print a sketch up drawing  in 3d
How to print a sketch up drawing in 3d
 
Google sketch up-tutorial
Google sketch up-tutorialGoogle sketch up-tutorial
Google sketch up-tutorial
 
7 types of presentation styles on line
7 types of presentation styles on line7 types of presentation styles on line
7 types of presentation styles on line
 
Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020Design pseudo codeweek 6 2019 -2020
Design pseudo codeweek 6 2019 -2020
 
Php introduction
Php introductionPhp introduction
Php introduction
 

Recently uploaded

Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
mahammadsalmanmech
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 

Recently uploaded (20)

Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
Question paper of renewable energy sources
Question paper of renewable energy sourcesQuestion paper of renewable energy sources
Question paper of renewable energy sources
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 

Data types in C programming

  • 1.
  • 2. Objectives • Be able to explain to others what a data type is • Be able to use basic data types in C programs • Be able to see the inaccuracies and limitations introduced by machine representations of numbers CoxSimple Data Types2
  • 3. What do you see? CoxSimple Data Types3
  • 4. What do you see? CoxSimple Data Types4
  • 6. CoxSimple Data Types6 Everything is Just a Bunch of Bits • Bits can represent many different things • Depends on interpretation • You and your program must keep track of what kind of data is at each location in the computer’s memory • E.g., program data types
  • 7. CoxSimple Data Types7 Big Picture • Processor works with finite-sized data • All data implemented as a sequence of bits • Bit = 0 or 1 • Represents the level of an electrical charge • Byte = 8 bits • Word = largest data size handled by processor • 32 bits on most older computers • 64 bits on most new computers
  • 8. CoxSimple Data Types8 Data types in C •Only really four basic types: • char • int (short, long, long long, unsigned) • float • double •Size of these types on •CLEAR machines: •Sizes of these types •vary from one machine •to another! Type Size (bytes) char 1 int 4 short 2 long 8 long long 8 float 4 double 8
  • 9. CoxSimple Data Types9 Characters (char) • Roman alphabet, punctuation, digits, and other symbols: • Encoded within one byte (256 possible symbols) • ASCII encoding (man ascii for details) • In C: char a_char = ’a’; char newline_char = ’n’; char tab_char = ’t’; char backslash_char = ’’;
  • 10. CoxSimple Data Types10 ASCII From “man ascii”: | 0 NUL| 1 SOH| 2 STX| 3 ETX| 4 EOT| 5 ENQ| 6 ACK| 7 BEL| | 8 BS | 9 HT | 10 NL | 11 VT | 12 NP | 13 CR | 14 SO | 15 SI | | 16 DLE| 17 DC1| 18 DC2| 19 DC3| 20 DC4| 21 NAK| 22 SYN| 23 ETB| | 24 CAN| 25 EM | 26 SUB| 27 ESC| 28 FS | 29 GS | 30 RS | 31 US | | 32 SP | 33 ! | 34 " | 35 # | 36 $ | 37 % | 38 & | 39 ' | | 40 ( | 41 ) | 42 * | 43 + | 44 , | 45 - | 46 . | 47 / | | 48 0 | 49 1 | 50 2 | 51 3 | 52 4 | 53 5 | 54 6 | 55 7 | | 56 8 | 57 9 | 58 : | 59 ; | 60 < | 61 = | 62 > | 63 ? | | 64 @ | 65 A | 66 B | 67 C | 68 D | 69 E | 70 F | 71 G | | 72 H | 73 I | 74 J | 75 K | 76 L | 77 M | 78 N | 79 O | | 80 P | 81 Q | 82 R | 83 S | 84 T | 85 U | 86 V | 87 W | | 88 X | 89 Y | 90 Z | 91 [ | 92 | 93 ] | 94 ^ | 95 _ | | 96 ` | 97 a | 98 b | 99 c |100 d |101 e |102 f |103 g | |104 h |105 i |106 j |107 k |108 l |109 m |110 n |111 o | |112 p |113 q |114 r |115 s |116 t |117 u |118 v |119 w | |120 x |121 y |122 z |123 { |124 | |125 } |126 ~ |127 DEL| Special control characters
  • 11. CoxSimple Data Types11 Characters are just numbers •What does this function do? Char fun(char c) { char new_c; if ((c >= ’A’) && (c <= ’Z’)) new_c = c - ’A’ + ’a’; else new_c = c; return (new_c); } return type procedure name argument type and name local variable type and name Math on characters! comparisons with characters!
  • 12. CoxSimple Data Types12 FP vs. Integer Results int i = 20 / 3; float f = 20.0 / 3.0; True mathematical answer: 20  3 = 6 2/3 i = ? f = ? 6 6.666667 Integer division ignores remainder FP arithmetic rounds result
  • 13. CoxSimple Data Types13 Integer Representations Base 2 Base 16 Unsigned 2’s Comp. 0000 0 0 0 0001 1 1 1 0010 2 2 2 0011 3 3 3 0100 4 4 4 0101 5 5 5 0110 6 6 6 0111 7 7 7 1000 8 8 -8 1001 9 9 -7 1010 A 10 -6 1011 B 11 -5 1100 C 12 -4 1101 D 13 -3 1110 E 14 -2 1111 F 15 -1 0000 0001 0010 0011 0100 0101 0110 011110001001 1011 1100 1101 1010 1110 1111 0 1 2 3 4 5 6 789 A D C B E F 0 1 2 3 4 5 6 789 10 11 12 13 14 15 0 1 -8 3 4 5 6 7 2 -7 -6 -5 -4 -3 -2 -1 Why one more negative than positive?
  • 14. CoxSimple Data Types14 Integer Representations Math for n bits: Define     1 0 2)(2 n i i i xxUB        2 0 1 1 22)(2 n i i i n n xxxTB  01 xxx n    sign bit 0=non-negative 1=negative Base 2 Base 16 Unsigned 2’s Comp. 0000 0 0 0 0001 1 1 1 0010 2 2 2 0011 3 3 3 0100 4 4 4 0101 5 5 5 0110 6 6 6 0111 7 7 7 1000 8 8 -8 1001 9 9 -7 1010 A 10 -6 1011 B 11 -5 1100 C 12 -4 1101 D 13 -3 1110 E 14 -2 1111 F 15 -1
  • 15. 15 Memory Layout of Records initials (2 bytes) married (1 byte) ss_number (4 bytes) • Fields are stored adjacently in memory. • Memory is allocated for records based on the order the fields are created. • Variables are aligned for easy reference. initials (2 bytes) ss_number (4 bytes) married (1 byte) Optimized for space Optimized for memory alignment 4 bytes / 32 bits 4 bytes / 32 bits