Question: Pointer Tasks This part of the assignment will give you a chance to perform some simple tasks with pointers. The instructions below are a sequence
Pointer Tasks
This part of the assignment will give you a chance to perform some simple tasks with pointers. The instructions below are a sequence of tasks that are only loosely related to each other. Start the assignment by creating a file named pointerTasks.cpp with an empty main function, then add statements in main to accomplish each of the tasks listed below. Some of the tasks will only require a single C statement, others will require more than one. For each step, include a comment in your program indicating which step you are completing in the following statements The easiest way to do this is copy and paste the below into your main function first, and then fill in your statements. Note: for steps and you will need to declare functions. These should be declared before main, not inside of main.
Create two integer variables named and
Create an int pointer named p
Store the address of in
Use to set the value of to
Using cout and display the value of
Using cout and the pointer p display the value of
Store the address of into
Use to set the value of to
Create two new variables: an int named temp, and an int pointer named p Use temp, and to swap the values in and this will take a few statements
Write a function with the following signature: void noNegatives int The function should accept the address of an int variable. If the value of this integer is negative then it should set it to zero. Note: you should declare th e noNegatives function BEFORE main, not inside of main.
Call the function twice: once with the address of as the argument, and once with the address of
Use p to display the values in and this will require both assignme nt statements and cout statements
Create an int array with two elements. The array should be named
Use p to initialize the first element of a with the value of
Use p to initialize the second element of a with the value of
Using cout, display the address of the first element in a
Using cout, display the address of the second element in a
Use p p and temp to swap the values in the two elements of array
first point at then point at After this the swapping st eps should look very similar to step
Display the values of the two elements. The first element should be the second
Write a function named 'swap' that accepts two integer pointers as argum ents, and then swaps the two integers that the pointers point to This functio n must be pass by pointer, ie int not pass by reference, ie int & Not : you should declare the swap function BEFORE main, not inside of main.
Call your swap function with the addresses of and then print their values. should be y should be
Call your swap function with the address of the two elements in array then print their values. should be should be
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
