
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
![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]](https://content.bartleby.com/qna-images/question/e5b392f2-339b-4262-bd19-d52d68056e99/4b6d112f-e936-400f-82cb-036aa2c3267c/nlwnyms_thumbnail.png)
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]

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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 3 images

Knowledge Booster
Similar questions
- Can you help me write a C++ program to do the following: Create a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1, 2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driverarrow_forwardWrite aJava function given an array of integers nums [passed by reference] and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.arrow_forwardCreate a function append(v, a, n) that adds to the end of vector v a copy of all the elements of array a. For example, if v contains 1,2, 3, and a contains 4, 5, 6, then v will end up containing 1, 2, 3, 4, 5,6. The argument n is the size of the array. The argument v is a vector ofintegers and a is an array of integers. Write a test driver.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY