Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use C++ to write the following code. BCS 230 Lab 9 CRN 90110, 90111 Fall 2018 JLi Objective: To learn to use pointer variables to
Use C++ to write the following code.
BCS 230 Lab 9 CRN 90110, 90111 Fall 2018 JLi Objective: To learn to use pointer variables to manipulate data of different types. Tasks: Write a program that performs the following tasks 1) Declare an int variable num and assign an integer value 12 to it. Declare a pointer variable numptr that points to num. Write statements using the address-of operator&) and dereferencing operator() to output the address of num, the value of num the address of numptE the value of nummPt and the value pointed to by numPtr Observe the output 2) Declare an int array arrayA with five elements, and initialize the eleme l to 9. Declare an int aray arrays with five elements, and initialize the elements to the even integers from 2 to 10 nts to the odd integers from e pointer variable pt t that points to arrayi. Declare a pointer variable ptiB that points to arrayB 4) Use a for statement to output the address and the value of each element of arrayA using pEEA and array subscript notation. 5) Use a tor statement to output the address and the value of each element of ar rayB using ptrs and pointer offset notation. Observe the address output of arzayA and arrayB. 6) Write a function printarray to output the contents of an array. The function accepts an int pointer variable for an array and an int variable representing the size of the array 7) Write a function swapArray and call it to swap the contents of azray and arrayB. The swapArray function should have two int pointer variables and one int variable representing the size of array. Two arrays have the same size. The function prototype is: void swap (intl.pa, int xpl, nt size); 8) After swap two arrays. call printArray function to check the results. ip
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started