Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question
100%
Write a program to swap the values of 2 arrays using pointers. Create a function (void
inputArray) to input the elements of the arrays.
For your function,
Receive parameter of pointer to an array from main
- fill the array by using the pointer parameter
Sample
void inputArray(int *arr)
for (...?..)
{
scanf("%d", arr.);
Modify the sample above, especially the bolded parts, (refer part 5 Array and Pointers]
In your main,
create array and pass it to inputArray() to fill up the elements
· Printout the array to check whether elements have been input from function
Use a for loop, temp variable and pointers to swap the elements of the arrays.
Pseudocode
int main ()
int size = 10;
int i, temp;
int arri[size);
int arr2[size);
input array for arr1 and arr2 using inputArray()
print arrays
for (loop)
temp = *(arr1_current_space);
*(arri_current_space) = *(arr2_current_space);
*(arr2_current_space) = temp;
print arrays
Modify the pseudocode above, especially all the bolded parts.
The swapping part you need to use pointer to go to current spaces in arrl and arr2 because
your initial pointer is at start of array. [refer part 5 Array and Pointers]
expand button
Transcribed Image Text:Write a program to swap the values of 2 arrays using pointers. Create a function (void inputArray) to input the elements of the arrays. For your function, Receive parameter of pointer to an array from main - fill the array by using the pointer parameter Sample void inputArray(int *arr) for (...?..) { scanf("%d", arr.); Modify the sample above, especially the bolded parts, (refer part 5 Array and Pointers] In your main, create array and pass it to inputArray() to fill up the elements · Printout the array to check whether elements have been input from function Use a for loop, temp variable and pointers to swap the elements of the arrays. Pseudocode int main () int size = 10; int i, temp; int arri[size); int arr2[size); input array for arr1 and arr2 using inputArray() print arrays for (loop) temp = *(arr1_current_space); *(arri_current_space) = *(arr2_current_space); *(arr2_current_space) = temp; print arrays Modify the pseudocode above, especially all the bolded parts. The swapping part you need to use pointer to go to current spaces in arrl and arr2 because your initial pointer is at start of array. [refer part 5 Array and Pointers]
Sample output
Before Swap:
Аrгay: 1
8
8.
5
6
54
5
68
6
Array: 2
After Swap:
5
65
4
2
Аггау: 2
5
65
68
6
4
2
Array: 1
8
5
6
54
expand button
Transcribed Image Text:Sample output Before Swap: Аrгay: 1 8 8. 5 6 54 5 68 6 Array: 2 After Swap: 5 65 4 2 Аггау: 2 5 65 68 6 4 2 Array: 1 8 5 6 54
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY