variables and types in objective-c and c programming

44
Paul Solt iPhoneDev.tv Variables and Types The buildings blocks of apps

Upload: paul-solt

Post on 22-May-2015

389 views

Category:

Education


1 download

DESCRIPTION

Course Link: http://skl.sh/11kA0im Website: http://iPhoneDev.tv Learn how variables and types work in Objective-C and C programming languages.

TRANSCRIPT

Page 1: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Variables and TypesThe buildings blocks of apps

Page 2: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Coffee

=+

Page 3: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Coffee

•17 ml water : 1 g coffee

•950 ml water / 17 ml/g = ?

•55.8 g coffee

Page 4: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

VariablesGive the CPU something to remember

Page 5: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

// Declare a variable to store waterfloat water;

// Store the amount of water to usewater = 950; // milliliters

// Display messageprintf("Brew %f milliliters of coffee", water);

Page 6: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int age = 26;

Page 7: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int age = 26;type

Page 8: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int age = 26;type name

Page 9: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int age = 26;type name expression

Page 10: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int age = 26;type name expression

assignmentoperator

Page 11: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int age = 26;

Page 12: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int age = 26;

26age

Page 13: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

Page 14: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

a

Page 15: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

a

b

Page 16: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b; b

5a

Page 17: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

5a

20b

Page 18: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

5a

205+b

b

Page 19: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

5a

205+20

b

Page 20: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

5a

255+20

b

Page 21: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

5a

25b

Page 22: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

5a-b

a

25b

Page 23: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

55-25

a

25b

Page 24: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

-205-25

a

25b

Page 25: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int a;int b;a = 5;b = 20;b = 5 + b;a = a - b;

-20a

25b

Page 26: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

TypesWhat kind of information are we storing?

Page 27: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

•short/int/long: -1,0,1•float/double: 3.14•char: ‘a’, ‘b’, ‘c’•pointers: int * (memory address)•struct: composition (x, y)

Page 28: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

short small = 12;int medium = 2000000;long large = 90133726844735000;

Page 29: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

float smaller = 3.14;double larger = 3.14159265359;

Page 30: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

char firstLetter = 'a';char percent = '%';

Page 31: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

Page 32: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0

Page 33: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0 18

Page 34: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0 18

Page 35: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544&x

0 18

Page 36: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0x5544

&x

18

Page 37: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0x5544

&x

18

Page 38: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0x5544 18*address

Page 39: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0x5544 27*address

Page 40: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

int *address = 0;int x = 18;address = &x;*address = 27;

address x

0x1234 0x5544

0x5544 27

Page 41: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

struct Point { int x; int y;};

...

struct Point a;a.x = 25;a.y = 100;

Page 42: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

struct Point { int x; int y;};

...

struct Point a;a.x = 25;a.y = 100;

(25, 100)y

x

Page 43: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv

•short/int/long: -1,0,1•float/double: 3.14•char: ‘a’, ‘b’, ‘c’•pointers: int * (memory address)•struct: composition (x, y)

Page 44: Variables and Types in Objective-C and C Programming

Paul Solt iPhoneDev.tv