Max Max - 11 days ago 5
Objective-C Question

How could i write a function in Objective - C which gets 3 parameters and in the first parameter is stored the sum of the 2nd and 3rd parameter?

I am new to Objective C programming and i would like to know the steps/approach of resolving this exercise.

Answer
-(void)myValue:(int *) sum istheSumOfFirst:(int)a andSecond:(int)b {
    *sum = a + b;
}

And you can call the function like

int sum;
[self myValue:&sum istheSumOfFirst:5 andSecond:3];
NSLog(@"%i", sum);

Console:$ 8

Comments