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.
Here the author tries to explain that the variable
will pass on it's value to the function
. And that a second variable within the function is declared,
, in order to store the value of the calculation, which is then supposedly returned.
circleArea(float theRadius) // [5.1]
theArea = 3.1416 * theRadius * theRadius; // pi times r square [5.4]
My question is I see that the variable
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
is then returned to
, which is then passed on to the function
. So essentially the value of
is just Pi multiplied twice to a variable that doesn't have a defined value, which is the variable
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.
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!