I am new to Objective C programming and i would like to know the steps/approach of resolving this exercise.
Asked
Active
Viewed 67 times
-1
-
Your question was down voted (by somebody else) because one of the rules for Stack Overflow is to not ask for book/tutorial/framework recommendations. I suggest you edit your question to focus on the problem and use google to search for resources. – EmilioPelaez Nov 23 '16 at 14:42
2 Answers
0
-(void)addingSumInto:(NSInteger *)sum byAddingValue:(NSInteger)integerOne andValue:(NSInteger)integerTwo{
//Here you can Do with these three parameters.
//As your question is unclear so lets add above three and then simply return them
*sum = integerOne + integerTwo;
}
Now in your main Method call above method like this..
NSInteger sum;
[self addingSumInto:&sum byAddingValue:99 andValue:155];
NSLog(@"%ld",sum);

Syed Qamar Abbas
- 3,637
- 1
- 28
- 52
-
Sorry for being unclear. So here it is : a function inside the main sends 3 arguments, so when this function is called it must have 3 parameters , right? In the 1st parameter will be stored the sum of the value of the 2nd and the 3rd parameter after which it will be printed by NSLog like NSLog(@"The sum of 2ndparam and 3rd parameter is: " , 1stparameter). I dont know how to solve this so i didnt write a format specifier in NSLog. I wanted the 1st parameter to be a pointer type. Btw. why did you use NSInteger? Is this a must when working with numbers of type int? – Max Nov 23 '16 at 15:11
-
Check this stack answer that why we use NSInteger instead of int.. http://stackoverflow.com/questions/4445173/when-to-use-nsinteger-vs-int – Syed Qamar Abbas Nov 23 '16 at 18:28
0
-(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

Krrish
- 2,256
- 18
- 21