learning obj-c do i need to know a lot of c (pointers)

Discussion in 'Mac Programming' started by pacific707, Feb 12, 2009.

  1. macrumors newbie

    Jan 9, 2007
    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
  2. Moderator emeritus


    Jul 24, 2002
    int* variable and int *variable are the same...
  3. thread starter macrumors newbie

    Jan 9, 2007
    so i can use them interchangeably? so peoplejust add the space in a different place for fun sometimes?
  4. macrumors G5


    Nov 25, 2005
    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.
  5. macrumors 68040


    Jan 10, 2005
    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:
    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:
    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. =)

  6. thread starter macrumors newbie

    Jan 9, 2007
    Thanks so much

    been trying to understand pointers and lots of examples do it different ways, this makes it so much more clear.

Share This Page