Link to home
Start Free TrialLog in
Avatar of UniqueData
UniqueDataFlag for United States of America

asked on

Question about asterisk

I have been 'programming' in Access and VBA for years and outside of High School and College programming classes years ago, that is the extent of my programming.  I am now trying to learn Objective-C to create Iphone apps.  I got a couple great books and found some great tutorial sites, but I have some 'basic' questions that I can not seem to find the answers to anywhere.  One of which is regarding the use of the asterisk.  One of my references mentions this is a method for using a pointer, but I don't understand why sometimes it is used and sometimes it is not.  In reference to they code below, it looks like there are two ways an asterisk is being used.  One is in front of a variable name, such as name, description, and imageURL.  The other is in the last line after 'NSString'.  

I am not a type that will just type something because I am told to.  I gotta understand why :)

Thanks in advance,

Michael
@interface Animal : NSObject {
	NSString *name;
	NSString *description;
	NSString *imageURL;
}
 
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *description;
@property (nonatomic, retain) NSString *imageURL;
 
-(id)initWithName:(NSString *)n description:(NSString *)d url:(NSString *)u;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of F. Dominicus
F. Dominicus
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of UniqueData

ASKER

but what about line #11 in the code above.  There is no variable name, just (NSString *)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AJVienna
AJVienna

Another example (plain C) which I hope you will find useful to understand pointers.
The * is used for declaring pointers and dereferencing them (to understand this look at the example).
The & is used to get the address (in memory) of another variable.
int a = 3, b = 4;
int *p = NULL;
p = &a; // p now points to the memory address a is stored in
*p=2;   // now we write 2 to the memory address p is pointing to
// a now contains 2
p = &b; // now p points to the address where b is stored.
*p=5;
// b now contains 5
 
// you can also have pointers to pointers
int **pp = NULL
pp=&p;
// now pp is pointing to the address of p
*pp=&a;
// now the memory at address of p is changed to point to a 
*p=10;
// thus the line above changes the memory add address a and gives 
// thus a is now 10.

Open in new window

Thank you much for your posts.  I guess the thing that threw me off on the (NSString *)d is that the * was within the (), I would expect it directly in front of the variable, but I think I get it.