Hello all,
This is my first post and I am a complete novice at C programming. I am trying to teach myself C programming and using "Programming in C" by Stephen G. Kochan 3rd Ed. My problem is that I have a pointer that points to an array and I want it to do (what I assumed) was a simple 'for' loop to cycle through the elements of the array using this code:
Code:
int main(void)
{
int array[3]={5,15,7};
int *arrPntr;
for (arrPntr = array; arrPntr<(arrPntr+2); arrPntr++)
printf("%i\n", *arrPntr);
getchar();
}
but it loops through the code and doesn't stop (an infinite loop until it crashes).
I have found a work around in :
Code:
for (arrPntr = array; arrPntr<&array[3]; arrPntr++)
but in my book, it says that the first example should work (for anyone who has the book it is Chap 11, page 262: Paraphrased "'valuesPtr > &values[99]' is the same as ' valuesPtr > values + 99'".
Could someone please tell me if:
1. I have made a mistake with my code (which I think is the case)
2. The text is incorrect or outdated, and if so please provide me with up to date information.
Thank you for any assistance you can offer.