1. I see %f is for float, %@ is for string. Is %d for anything? Which % is for double? Which % is for BOOL?

  2. What is the different between double and float? When I put

    float flow=-8.1234567890123456789; //4 bytes floating point
    double dobble=-8.1234567890123456789;  //8 bytes floating point
    NSLog(@"flow is %f and dobble is %f", flow, dobble);
    

    The output is the same for flow and dobble.

  3. I can write "int a, b;" to declare two ints. Why can't I write "NSString* personOne, personTwo;"?

  4. How do I declare a bitwise variable and manipulate it with &=, <<, ^?

Edited 3 Years Ago by MareoRaft

FIVE. To create my own class, is the following correct?

(i) I create a header file Myclass.h where I declare the class, the variables it holds, and the methods I want to make for it.
(ii) I create an Obj-C (not sure what you call this one) file Myclass.m where I write the code for the methods defined in Myclass.h.
(iii) In my regular Obj-C program, which is named program.m, I #import "Myclass.h" and then I am free to start using my class!

Edited 3 Years Ago by MareoRaft

  1. NSLog works much like printf; %d is for integers, %f and %F work for both floating point types, and BOOL is just an integer, so use %d.

  2. double can handle more precision; try a number with more digits.

  3. That's how the language works; you have to write NSString *personOne, *personTwo;. It might help to think of "pointer-ness" as a property of the variable, not the type.

  4. Any integer type will do, like int i = 23; i <<= 2; should leave 92 in i.

Comments
if %d is for integers, what is %i for?

Also %@ is for pointers. Which means any class that implements - (NSString *)description will have a meaningful output.

This article has been dead for over six months. Start a new discussion instead.