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

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
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
 
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
 
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
 
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.
 
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
 
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

See if to can "test out" of the prereq with your current knowledge. Can't hurt to ask.

-Lee
 
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'.
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
 
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
 
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
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.