![]() |
| ||
| Using a variable as an array's index? Hey all, First post here and hello to everyone. I've been studying C for a few months now, and everythnig has been making sense and I'm enjoying the challenge of learning to progeam. Ther is one thing that keeps eluding my understanding of arrays, and that's using a variable in a for loop such as this: #include <stdio.h> No matter how I look at this, I can't seem to grasp the function of the variable i in this bit of the code, array[i]. I can see that the loop runs up to 9, that the value of i is being assigned to each element in the array as the loop runs, that the variable i is being used as the index for the array, but why is the i in the array[i] part? Apologies if this is so basic, but it's driving me mad. Strange thing is, I find pointers to be easier to grasp tham this one thing. lol Cheers. |
| ||
| Re: Using a variable as an array's index? Sometimes you just have to look at something for a while before it clicks. Adding extra printf statments can sometimes help to see what is going on. #include <stdio.h> |
| ||
| Re: Using a variable as an array's index? Ahh, now I see it. :) I have a tendency to look too closely at things. Thanks a million for that, it helps in the way you showed your example. Cheers. |
| All times are GMT -4. The time now is 9:23 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC