KEMBAR78
Numbers and Values in Objective-C and C Programming | PDF
Paul Solt
iPhoneDev.tv
Numbers
The data behind our apps
Paul Solt
iPhoneDev.tv
Overview
•Integers (27)
•printf()
•Floating-point numbers (3.14)
•Math libraries
Paul Solt
iPhoneDev.tv
Integers
•char: ‘a’,‘b’,‘c’
•short: 32,000
•int: 2,000,000,000
•long: 9,000,000,000,000,000,000
•long long: 9,000,000,000,000,000,000
Paul Solt
iPhoneDev.tv
Integers
•char: ‘a’,‘b’,‘c’ (8 bits = 1 byte)
•short: 32,000 (16 bits)
•int: 2,000,000,000 (32 bits)
•long: 9,000,000,000,000,000,000 (32 or 64 bits)
•long long: 9,000,000,000,000,000,000 (64 bits)
Paul Solt
iPhoneDev.tv
Overflow
99999
99999
10000000
10000000
Paul Solt
iPhoneDev.tv
printf
•Formatted text
•Tokens
•n (i.e. newline or return)
%d int
%c char
%f float/double
%s char * (i.e. text)
%ld long
Paul Solt
iPhoneDev.tv
Math
8 + 4 * 2 = ?
(8 + 4) * 2 = ?
Paul Solt
iPhoneDev.tv
Integer Division
5 / 2 = ?
5 % 2 = ?
Paul Solt
iPhoneDev.tv
Integer Division
5 / 2 = 2
5 % 2 = 1
Paul Solt
iPhoneDev.tv
Floating-point Numbers
•float: 3.14
•double: 3.141592653
Paul Solt
iPhoneDev.tv
Floating-point Numbers
•float: 3.14 (32 bits)
•double: 3.141592653 (64 bits)
Paul Solt
iPhoneDev.tv
Math Library
#include <stdlib.h>
abs(-13); // absolute value
#include <math.h>
cos(60 * M_PI / 180.0); // radians
Paul Solt
iPhoneDev.tv
Review
•Integers
•printf()
•Floating-point numbers
•Math libraries
Paul Solt
iPhoneDev.tv

Numbers and Values in Objective-C and C Programming