#import <Foundation/Foundation.h>
BOOL areIntsDifferent( int thing1, int thing2 ) {
if (thing1 == thing2) {
return (NO);
} else {
return (YES);
}
}
NSString *boolString (BOOL yesNo) {
if (yesNo == NO) {
return( @"NO" );
} else {
return( @"YES" );
}
}
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);
}
This is the whole program. This is not terribly complicated, but it illuminates the general problem that I am facing is understanding pointers. In this situation, is the return value of the boolString function a pointer because there is no memory allocated to hold the string? And if so, why is notIntsDifferent returns a pointer value to a BOOL value? Is it possible to rewrite this program so that the return value of boolString is a string and not a pointer to a string? If yes, how? I tried to fix *, but then I got a compiler error.
source
share