Pointer...eh?

This is a discussion on Pointer...eh? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by elnerdo
Don't try to be a smart.alleck
Look, the point of that program is to output the ...

This most definately does display the numbers in an array. How exactly doesn't this display the contents of the array? You do know what an array is, right? You should then know that the variable a is in fact an array. You should then also know that "cout<<a[i]" is outputting the contents of the array at that element.

Again, who's the idiot?

Originally Posted by elnerdo

The one with the pointer accomplishes that task and uses one less variable than the one with the array and the index number.

No it doesn't. It could. But there's nothing guarinteeing that it does in fact only use one variable. Perhaps you should actually look at you code. Here, I'll help, because you seem to be mistaken:

There is absolutely nothing that states that the compiler must optimize that check. Therefore, you do in fact use two variables every single time through your loop. One is the pointer. The other is the variable a.

Again, your compiler might optimize that test. But nothing at all in the C++ language says that will happen. Therefore, by the language itself, you are in fact using two variables every time through the loop.

It's alright to be a smart ass, if you know what you're talking about. Otherwise you just end up looking like a dumbass.

Theoretically, it would take the initial address, add the fixed value 10 to it, and replace all other checks with that new number. So if the address were "10", it would do a one-time add of 10 to it, making it "20", and then test against "20" every time through the loop. But again, it doesn't have to do that at all. Also, were 'a' an actual pointer, rather than an array name, it would most likely NOT optimize that, as the pointer 'a' could be changed in the loop, so it would definately test against it every single time through.

Originally Posted by elnerdo

Oh, I'm sorry, I didn't see the cout in there.

for(ptr = a; ptr < 10; ptr++)
printf("%d",*ptr);
printf("\n");

There, happy? now it's one variable plus a static against two plus a static.

[amused] I'll be amazed if this displays anything other than a newline. [/amused]

Like I said, you can only be a smart ass if you know what you're talking about.