pointers in cpp 2
pointers in cpp 2
Let’s look at a program that declares an integer array. We’ll count how many elements are
odd and how many even and print it to the console.
Why not try to use pointers for it? Later, we’ll explain just why this might be more efficient.
Here, we are incrementing both the array index and the pointer in the for loop. The
functionality is the same. We are initializing the pointer to the first element of the array.
When reading this code, be careful to consider that even and odd, although declared in the
same line, are separate variables from the pointer.