Create two integer variables x and y and an integer array


Problem 1. (Basic Pointers and Pointer Arithmetic) Write a program that will do the following:

1. Create two integer variables x and y, and an integer array z[5]

2. Set the variable x equal to 5, and the variable y equal to 10

3. Save the following values in the array: 1, 2, 4, 8, 16

4. Print to screen the address of each of the variables, x, y, and the start of the array z

5. Create a pointer named testPtr and point it to the variable x

6. Print to screen the value stored in variable x using only your pointer testPtr

7. Add six to the value stored in x using only your pointer testPtr

8. Print to screen the value stored in variable x using only your pointer testPtr

9. Test to see if the value stored in variable x is larger than y, using only the variable y and the testPtr. If it is, print to screen "x > y", otherwise print "y < x"

10. Now, change testPtr to Point to the first entry of the array z

11. Using only testPtr, use a counter and for loop to print all the value in the array (do not use the array).

Problem 2. (Pointers and Functions)Write a void function called swap that accepts as inputs two integer variables and swaps their values. For example, if I had a variable a = 5 and b = 10, after calling swap with variables a and b; a = 10 and b = 5. Note this will require writing the function such that it uses pointers since we want to change the original variables and return nothing (void).

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: Create two integer variables x and y and an integer array
Reference No:- TGS01155031

Now Priced at $60 (50% Discount)

Recommended (99%)

Rated (4.3/5)

A

Anonymous user

5/12/2016 1:19:43 AM

The task is all about Basic Pointers and Pointer Arithmetic. Question: Write down a program which will do the given: 1) Prepare two integer variables x and y, and an integer array z[5] 2) Set out the variable x equivalent to 5, and the variable y equivalent to 10 3) Save the given values in the array: 1, 2, 4, 8, 16 4) Print to screen the address of each of the variables, x, y, and the beginning of the array z 5) Prepare a pointer named testPtr and point it to the variable x 6) Print to screen the value stored in variable x employing only your pointer testPtr 7) Add 6 to the value stored in x employing only your pointer testPtr 8) Print to screen the value stored in variable x employing only your pointer testPtr