last array question before moving on.

Discussion in 'Mac Programming' started by larswik, Dec 23, 2010.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    These 2 have the same meaning, yes?
    Code:
    array[0] = '4';
       and
    *array = '4';
    
    The *array points to the value stored in the first variable of the array string? (hope my terminology is correct.

    -Lars
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Yes. When you have an array, you're really just storing a pointer to the base of the array. So &array[0] will be the same address as what's stored in array. The [] operator takes the first operand, then adds the second operand (what's between the brackets) times the size of the type the first operand points to, yielding a new address. The type will be what the first operand points to. The * takes the address stored in the single operand, and dereferences it (getting or storing a value there) with the type of the operand. In your example if array has the pointer 0xF, then:
    array[0] with array being a char * will be the address:
    15+(0*sizeof(char))
    dereferenced. This will obviously be the same address as array is storing.

    -Lee
     
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    Thanks for the detailed explanation.

    It hard not having programing friends to talk to. Although I read the terminology in the book but don't speak it to other people I forget a lot of what they mean, even though I understand the code, for the most part.

    Thanks Lee.

    -Lars
     
  4. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #4
    You are right about having someone to talk to about programming. Are you sure you know noone who's interested in the subject? I must say that my knowledge and insights grew tremendously from so-called "pair programming" at work. I't one thing to look at someone else's code, or have someone else take a look at yours, but the process of constructing the code while commenting each other on the fly has been the most influential thing in my programming career. Not so much for the syntactical details, but especially for the thoughts behind the code.

    I'll go so far as to say it compares to a musical jamsession. You still need to practice alone on your instrument of choice to hone your technical abilities, but playing together with someone else is not rewarding and motivating, and it can change the way you think about music.
     
  5. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    Sander- I agree and that is why I signed up for programming class. I wanted to take C even though I will finish the book before class starts Jan 24th. But I had to sign up for the prerequisite first, Turbo Pascal! That's not even on the Mac!

    I started learning Python and it was 'print', then a little Obcject-C and it was 'NSLog', now C and it is 'printf' and next year Pascal 'writeln'.

    -Lars
     
  6. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
    See if to can "test out" of the prereq with your current knowledge. Can't hurt to ask.

    -Lee
     
  7. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #7
    Never hurts to be multilingual! ;)

    I must say it is really strange to see Turbo Pascal still being used for anything. Even by the mid-80s it was going out of favor. My first college programming class (~1985), previously taught in Pascal, was in Modula-2 as Pascal derivative.

    B
     
  8. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #8
    I can't talk to the teacher to 'test out', I convinced a friend who wanted to learn how to program iphone apps to start with me. So, I can't test out and leave him all by himself.

    The class is 'Programming Fundamentals'. They want to get you exposed to everything before moving to C. By the time I finish this class I will have a good understanding of C since I plan to continue to write apps and practice till I have a good solid understanding. Maybe then I can hope over C and then onto either iPhone Programming or C++

    -Lars
     
  9. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #9
    Pascal isn't bad, just not used other than for teaching. I had to learn it to write a compiler for it in a university course.

    -Lee
     
  10. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #10
    If I could run Turbo Pascal on my MacBook Pro that would be better. Otherwise I will have to sit on the Lab they have and write the code on those Window's machines.

    -Lars
     

Share This Page