Question: 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
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 numptr, the value of nummPtr, and the value pointed to by numPtr. Observe the output. 2) Declare an int array arrayA with five elements, and initialize the elements to the odd integers from 1 to 9. Declare an int array arrayB with five elements, and initialize the elements to the even integers from 2 to 10. 3) Declare a pointer variable ptrA that points to arrayA. Declare a pointer variable ptrB that points to arrayB. 4) Use a for statement to output the address and the value of each element of arrayA using ptrA and array subscript notation. 5) Use a for statement to output the address and the value of each element of arrayB using ptrB and pointer offset notation. Observe the address output of arrayA and arrayB. 6) Write a function printArray to output the contents of an array. The function accepts an int pointer variable and an int variable representing the size of the array. 7) Write a function swapArray and call it to swap the contents of arrayA 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(int *pa, int *pb, int size); 8) After swap two arrays, call printArray function to check the results.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
