Hi everyone,
I have two questions two ask. The first one regarding functions and the second one relates to printing.
Ok so I am reading the online eBook from CocoaLab, BecomeAnXcoder. I am a noob to programming and after reading through a few books this seems to work the best for me, so I'll be using two examples from the book.
The numbers in the comments within the code are used in the book to refer to examples.
Example 1:
------------------------------
Here the author tries to explain that the variable
theRadius
will pass on it's value to the function
circleArea()
. And that a second variable within the function is declared,
theArea
, in order to store the value of the calculation, which is then supposedly returned.
/[5]
circleArea(float theRadius) // [5.1]
{
float theArea;
theArea = 3.1416 * theRadius * theRadius; // pi times r square [5.4]
return theArea;
}
My question is I see that the variable
theRadius
is declared, but I don't see a value defined for it. I am assuming that after
3.1416 * theRadius * the Radius
, which is equal to
theArea
,
theArea
is then returned to
(float theRadius)
, which is then passed on to the function
circleArea()
. So essentially the value of
theArea
is just Pi multiplied twice to a variable that doesn't have a defined value, which is the variable
theRadius
.
Is this correct?
Sorry if that was a really redundant explanation.
My second question is a lot simpler, I just want to know the difference between
%i %d and %f
.
I know that %f is used for float, and that %i is for intergers, but in the book he uses %d? He says d is short for decimals, but he seems to be using them for integers.
See:
//[5]
int x, integerToDisplay;
x = 1;
integerToDisplay = 5 + x;
NSLog(@"The value of the integer is %d.", integerToDisplay);
why is %d used instead of %i? and are there any other % with letters that I should know of?
Thank you very much for all your help in advance and sorry if the post comes out looking weird and for any redundant explanations!
Thanks again,
- Danny