When calling a swap function to swap the value of the two arrays, how do I add the reference to the calling statement without giving me an error? Also, I have to use pointers for this assignment. Here...


When calling a swap function to swap the value of the two arrays, how do I add the reference to the calling statement without giving me an error? Also, I have to use pointers for this assignment.


Here is the code:


const int S = 10;


//Pre-condition: two c strings of the same size


//Post-condition: swap the values of the c strings



void swapArr(char array1[ S], char array2[ S]) {

 int size = 0;
 for (int i = 0; array1[1] != '\0'; i++) {
  size++;
 }

 char* value = new char;
 value = new char [size];
 //Loop fusion
 for (int i = 0; i < size;="" i++)="">
  //Swap the values
  value[i] = array1[i];
  array1[i] = array2[i];
  array2[i] = value[i];
 }

}

int main(){

char array1[S]= { "Hello" };
 char array2[S] = { "World"};

//For some reason the swap function is not working


swapArr(& array1[S], & array2[S]);

 for (int i = 0; array1[i] != '\0'; i++) {
  std::cout <>
 }


}



Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here