0% found this document useful (0 votes)
2 views

pointers in cpp 2

The document discusses a C++ program that utilizes pointers to count odd and even elements in an integer array. It explains how to initialize a pointer to the first element and the process of reversing the array elements using begin and end pointers. The document emphasizes the efficiency of using pointers in array manipulation.

Uploaded by

movidod859
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

pointers in cpp 2

The document discusses a C++ program that utilizes pointers to count odd and even elements in an integer array. It explains how to initialize a pointer to the first element and the process of reversing the array elements using begin and end pointers. The document emphasizes the efficiency of using pointers in array manipulation.

Uploaded by

movidod859
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Pointers in C++

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.

This program declares an


integer array and prints it. It
uses pointers begin and end
to reverse the elements of
the array, swapping the first
with the last, the second
with second-last, meeting in
the middle by incrementing
the begin pointer and
decrementing the end
pointer.

You might also like