Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Functions in Objective-C and C Programming

442
views

Published on

Website: http://iPhoneDev.tv

Learn about functions which allow you to organize your code into chunks. Functions allow you to delegate work between different blocks of code.

1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
442
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
15
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. Paul SoltiPhoneDev.tvFunctionsInstruction manuals for computers
• 2. Paul SoltiPhoneDev.tvOutline•Functions•Stack Frame•Recursion•Debugging•GlobalVariables
• 3. Paul SoltiPhoneDev.tv
• 4. Paul SoltiPhoneDev.tvDesk1. Build small drawer2. Build large drawer3. Build desk frame4. Insert small drawer5. Insert large drawer
• 5. Paul SoltiPhoneDev.tvArea = A x BAreaAB
• 6. Paul SoltiPhoneDev.tvint area(int sideA, int sideB)
• 7. Paul SoltiPhoneDev.tvint area(int sideA, int sideB)return type
• 8. Paul SoltiPhoneDev.tvint area(int sideA, int sideB)namereturn type
• 9. Paul SoltiPhoneDev.tvint area(int sideA, int sideB)name parameterreturn typeparameter
• 10. Paul SoltiPhoneDev.tvint area(int sideA, int sideB)
• 11. Paul SoltiPhoneDev.tvint area(int sideA, int sideB){int result = sideA * sideB;return result;}
• 12. Paul SoltiPhoneDev.tvint total = area(4, 2);
• 13. Paul SoltiPhoneDev.tvint total = area(4, 2);arguments
• 14. Paul SoltiPhoneDev.tvint total = area(4, 2);8arguments
• 15. Paul SoltiPhoneDev.tvint total = area(4, 2);
• 16. Paul SoltiPhoneDev.tvStack Frame•“Sandbox”•LocalVariables
• 17. Paul SoltiPhoneDev.tvStack Frame•“Sandbox”•LocalVariablesmain()total = area(4,2);
• 18. Paul SoltiPhoneDev.tvStack Frame•“Sandbox”•LocalVariablesmain()total = area(4,2);area(4,2)sideA = 4sideB = 2result = 8
• 19. Paul SoltiPhoneDev.tvStack Frame•“Sandbox”•LocalVariablesmain()total = area(4,2);
• 20. Paul SoltiPhoneDev.tvStack Frame•“Sandbox”•LocalVariablesmain()total = 8;
• 21. Paul SoltiPhoneDev.tvStack Frame•“Sandbox”•LocalVariables
• 22. Paul SoltiPhoneDev.tvArea
• 23. Paul SoltiPhoneDev.tvRecursionSpace Shuttle: CountdownTimer1. Display number2. Subtract one3. Repeat steps 1 and 2 (until 0) STS-110, NASA
• 24. Paul SoltiPhoneDev.tvRecursion
• 25. Paul SoltiPhoneDev.tvRecursionvoid countDown(int number) {if(number == 0) {printf("Take off!n");} else {printf("T-minus %d secondsn", number);int nextNumber = number - 1;countDown(nextNumber);}}
• 26. Paul SoltiPhoneDev.tvRecursionvoid countDown(int number) {if(number == 0) {printf("Take off!n");} else {printf("T-minus %d secondsn", number);int nextNumber = number - 1;countDown(nextNumber);}}
• 27. Paul SoltiPhoneDev.tvRecursionvoid countDown(int number) {if(number == 0) {printf("Take off!n");} else {printf("T-minus %d secondsn", number);int nextNumber = number - 1;countDown(nextNumber);}}
• 28. Paul SoltiPhoneDev.tvStack Frame
• 29. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)
• 30. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)
• 31. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)
• 32. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)countDown(3)nextNumber = 2countDown(2)
• 33. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)countDown(3)nextNumber = 2countDown(2)countDown(2)nextNumber = 1countDown(1)
• 34. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)countDown(3)nextNumber = 2countDown(2)countDown(2)nextNumber = 1countDown(1)countDown(1)nextNumber = 0countDown(0)
• 35. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)countDown(3)nextNumber = 2countDown(2)countDown(2)nextNumber = 1countDown(1)countDown(1)nextNumber = 0countDown(0)countDown(0)take off!
• 36. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)countDown(3)nextNumber = 2countDown(2)countDown(2)nextNumber = 1countDown(1)countDown(1)nextNumber = 0countDown(0)
• 37. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)countDown(3)nextNumber = 2countDown(2)countDown(2)nextNumber = 1countDown(1)
• 38. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)countDown(3)nextNumber = 2countDown(2)
• 39. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)countDown(4)nextNumber = 3countDown(3)
• 40. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)countDown(5)nextNumber = 4countDown(4)
• 41. Paul SoltiPhoneDev.tvStack Framemain()startNumber = 5countDown(5)
• 42. Paul SoltiPhoneDev.tvStack Frame
• 43. Paul SoltiPhoneDev.tvCountDown!
• 44. Paul SoltiPhoneDev.tvGlobalVariablesint total = 10resetTotal()total = 0;updateTotal()total = total + 1;
• 45. Paul SoltiPhoneDev.tvGlobalVariables
• 46. Paul SoltiPhoneDev.tvReview•Functions•Stack Frame•Recursion•Debugging•GlobalVariables
• 47. Paul SoltiPhoneDev.tv