Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

pacific707

macrumors newbie
Original poster
Jan 9, 2007
4
0
I am trying to learn Objective-c and have picked up a couple of books. both say i should learn some basic c before I read them. I have been a filemaker developer for years and have some basic skills at php. so i understand the universal concepts like variables, loops, functions, compiling, etc. I am having a hard time getting pointers because of the positioning of the * or something. Sometimes the * is by the variable and sometimes its a space away ( int* variable or int *variable )
anyway its is necessary that i learn this down pat or can i just move on? Where is a good explanation about pointers?
Is there a good source for learning just the amount of c I need before jumping into objective-C?

any help appreciated thanks
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
Sometimes the * is by the variable and sometimes its a space away ( int* variable or int *variable )
anyway its is necessary that i learn this down pat or can i just move on? Where is a good explanation about pointers?

It doesn't make a difference whether you write "int* variable" or "int *variable" or "int * variable" or "int*variable"; they all mean exactly the same thing to the compiler. The last two are quite horrible because they look like a multiplication, and therefore make your code hard to read. I use "int* variable" if the emphasis is on "variable" pointing to one or more integers, and "int *variable" if the emphasis is on an integer that is somewhere and can be reached through the pointer "variable", but that is just style.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
I'll jump in and say:
1) Pointers are critical in C, C++, and Objective-C. You should definitely know how to use them, and what the * and & operators do, etc. if you want to pursue these languages. There are other languages that use pointers in different ways, but knowing the C-style syntax obviously mostly applies to these 3 languages.

2) There is no difference in meaning based on where the * is placed when declaring pointer variables. As stated above, this is generally a matter of style. I always like to keep the * by the name of the variable, so it is clear in a case like this:
Code:
int x,y,*z,*a,b,c,*d;
which is which (i'm not saying that's good style, either, just an example) vs. something like this:
Code:
int* x,y,z;

In the first example, it is pretty clear which variables are int * and which are int, in the second... well, once you "know", it's clear that x is the pointer, and y and z are not... but putting the * next to the type instead of the variable might mislead some newcomers into thinking that you are declaring a list of int *s instead of one int * and two ints.

3) If the positioning of the * in declarations is the hardest thing about pointers for you, you're much better off than I was when I started learning about them. =)

-Lee
 

pacific707

macrumors newbie
Original poster
Jan 9, 2007
4
0
Thanks so much

been trying to understand pointers and lots of examples do it different ways, this makes it so much more clear.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.