Amazon.com Widgets Trying to understand the logic of void
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 18, 2013, 09:18:32 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 3
| | |-+  Trying to understand the logic of void
Pages: [1]   Go Down
Print
Author Topic: Trying to understand the logic of void  (Read 470 times)
jmartins
Newbie
*
Posts: 1


Email




« on: July 05, 2012, 10:38:05 AM »

As I am working through this I'm getting an understanding but when it gets to the void area I am stuck.  It says in the book "If the method returns no value, you indicate that using the type void"

My understanding is when you run this program it prints the fraction of 1/3 on the screen.  Is that not a value being returned if its being displayed ? 

It works and still displays it so my difficulty is understanding why is printing on the screen not considered a value being returned ?
Logged
fujilla
Global Moderator
Sr. Member
*****
Posts: 270


WWW




« Reply #1 on: July 05, 2012, 11:01:21 AM »

Although I only have the 3rd edition, the chapters pretty much follow the same flow I believe, therefore:

Looking at Program 3.4, when it prints to the log "The value of myFraction is 1/3", the numerator and denominator values which are being displayed actually come from the getter methods which return "int" values, not "void" values:

Code: (Objective-C)
NSLog (@"The value of myFraction is: %i/%i", [myFraction numerator], [myFraction denominator]);

Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.