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

pointers in cpp 4

The document discusses functions that operate on integer arrays using pointers, including squaring elements and finding the largest or smallest values. It highlights the use of a while loop for iterating through the array elements via pointers. Additionally, it mentions a simple method for swapping elements using a temporary variable.

Uploaded by

movidod859
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

pointers in cpp 4

The document discusses functions that operate on integer arrays using pointers, including squaring elements and finding the largest or smallest values. It highlights the use of a while loop for iterating through the array elements via pointers. Additionally, it mentions a simple method for swapping elements using a temporary variable.

Uploaded by

movidod859
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

In the next exercise, we wrote a function that takes an integer array, or rather, a pointer to it,

its size, and pointer to another function that squares the elements of the array.

And here is the expected output:

What about finding the biggest or smallest elements in arrays? We can use pointers for that
too. Let’s initialize and declare an array, use a pointer to find the greatest element in it and
print its value:

We could have also used a


version of the for loop with
incrementing the pointer, but a
while loop is simpler in this
case. We are starting fom the
first element in the array, and
then incrementing the pointer,
iterating during the whole
length of the array.

In the following example, we will take a look at simple swapping of elements. Just like in
regular examples without pointers, it is done with a variable that temporarily holds one

You might also like