Max Max - 1 year ago 91
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 Source
-(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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download