Flaxer Eli - Computer Appl
Ch 5 - 1
Chapter 5
The C Programming Language
Types, Operators and Expressions
Computer Application
Flaxer Eli - Computer Appl
Ch 5 - 2
Outline
Data Types and Sizes Constants Declaration and Qualifier Arithmetic Operations Relational and Logic Operations Type Conversions Increment and Decrement Operations Bitwise Operations Assignment and Expressions Conditional Expressions Order of Evaluation
Flaxer Eli - Computer Appl
Ch 5 - 3
Data Type and Size Type signed unsigned char 8 2’com 8 short 16 2’com 16 long 32 2’com 32 int 16/32 2’com 16/32 float 32 fp x double 64 fp x long double 80 fp x
Flaxer Eli - Computer Appl
Ch 5 - 4
Constant
Type signed unsigned short 1234 1234U long 1234L 1234UL float 123.4f x double 123.4 x long double 123.4L x
Type hexa
- ctal
integer 0x30FF 0377
Flaxer Eli - Computer Appl
Ch 5 - 5
Amazing Example
#include <ansi_c.h> void main() { char x; unsigned char y; float z; int A; double B, C, D; x = 127; y = 1; z = -1.75; x = x+2; y = y-2; memcpy (&A, &z, 4); B = 2147483647 + 2; C = 2147483647 + 2U; D = 2147483647; D = D + 2; printf("%d %d %08x\n", x, y, A); printf("%12.0f %12.0f\n", B, C); printf("%12.0f\n", D); getchar(); }
Flaxer Eli - Computer Appl
Ch 5 - 6
Amazing Example FP
##include <ansi_c.h> void main() { int k; float X, Y, Z; double A, B, C; X = 1.0; for (k=0; k<100000; k++) X+=1e-8; Y = 0.0; for (k=0; k<100000; k++) Y+=1e-8; Z = 1.0; Z += 100000*1e-8; printf("%12.8f %12.8f %12.8f\n", X, Y, Z); A = 1.0; for (k=0; k<100000; k++) A+=1e-8; B = 0.0; for (k=0; k<100000; k++) B+=1e-8; C = 1.0; C += 100000*1e-8; printf("%12.8f %12.8f %12.8f\n", A, B, C); }