I don't quite understand why you defined this in the main part of the file in program 13.14.
void exchange (int *pint1, int *pint2);
This
void exchange (int *pint1, int *pint2)
{
int temp;
temp = *pint1;
*pint1 = *pint2;
*pint2 = temp;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
int i1 = -5, i2 = 66, *p1 = &i1, *p2 = &i2;
NSLog(@"i1 = %i, i2 = %i", i1, i2);
exchange(p1, p2);
NSLog(@"i1 = %i, i2 = %i", i1, i2);
exchange(&i1, &i2);
NSLog(@"i1 = %i, i2 = %i", i1, i2);
Works just a fine as
void exchange (int *pint1, int *pint2)
{
int temp;
temp = *pint1;
*pint1 = *pint2;
*pint2 = temp;
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
void exchange (int *pint1, int *pint2);
int i1 = -5, i2 = 66, *p1 = &i1, *p2 = &i2;
NSLog(@"i1 = %i, i2 = %i", i1, i2);
exchange(p1, p2);
NSLog(@"i1 = %i, i2 = %i", i1, i2);
exchange(&i1, &i2);
NSLog(@"i1 = %i, i2 = %i", i1, i2);
You mention something about this I think earlier in the chapter, but I don't quite get it still.
You say we should put them in a different sheet and just import them, so "void exchange (int *pint1, int *pint2);" isn't necessary right?
Thanks
Q~