using *-symbol

Joined
Oct 4, 2011
Messages
6
Reaction score
0
Points
1
Tell me please why we place * symbol before boolString and don't do it before areIntsDifferent? Where can I find rules of using * ?

Code:
#import <Foundation/Foundation.h>

// returns NO if the two integers have the same
// value, YES otherwise

BOOL areIntsDifferent (int thing1, int thing2)
{
    if (thing1 == thing2) {
        return (NO);
    } else {
        return (YES);
    }
	
} // areIntsDifferent


// given a YES value, return the human-readable
// string "YES". Otherwise return "NO"

NSString *boolString (BOOL yesNo)
{
    if (yesNo == NO) {
        return (@"NO");
    } else {
        return (@"YES");
    }
	
} // boolString


int main (int argc, const char *argv[]) 
{
    BOOL areTheyDifferent;
	
    areTheyDifferent = areIntsDifferent (5, 5);
	
    NSLog (@"are %d and %d different? %@", 
           5, 5, boolString(areTheyDifferent));
	
    areTheyDifferent = areIntsDifferent (23, 42);
	
    NSLog (@"are %d and %d different? %@", 
           23, 42, boolString(areTheyDifferent));
	
    return (0);
	
} // main
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
Tell me please why we place * symbol before boolString and don't do it before areIntsDifferent? Where can I find rules of using * ?

In the first case you are returning a pointer to a NSString. In the second case you are returning a BOOL value.

To learn more, get a C or Objective-C programming book to learn about the language. We're not going to teach you it here.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top