Alex Rivera | Logout

When should you NOT use the asterisk (*) when declaring a variable in Objective C

Asked 2009-07-23T15:29:07.893
10

I have just started learning objective c and the asterisk is giving me some trouble. As I look through sample code, sometime it is used when declaring a variable and sometimes it is not. What are the "rules" for when it should be used. I thought it had something to do with the data type of the variable. (asterisk needed for object data types, not needed for simple data types like int) However, I have seen object data types such as CGPoint declared without the asterisk as well? Is there a definitive answer or does it have to do with how and what you use the variable for?

Edit
Report

2 Answers

7

I think you should read a bit on C programming first. Objective-C is a superset of C. The reason why you don't use * for declaring CGPoint is because CGPoint is a struct, take a look in the CGGeometry.h header file.

answered 2009-07-23T15:54:31.990
6

The asterisk indicates the variable is a pointer to a datatype.

You should look into pointers for more information. They are a very important and fundamental aspect of programming.

answered 2009-07-23T15:31:30.087

Your Answer