Question: Problem 4: What does the following program print and why? Be sure to explain why each line of output prints the way it does to
Problem 4: What does the following program print and why? Be sure to explain why each line of output prints the way it does to get full credit.
#include
void swap1(int* a, int *b) { int* temp = a; a = b; b = temp; }
void swap2(int* a, int *b) { int temp = *a; *a = *b; *b = temp; }
int main() { int array[6] = { 5, 3, 4, 17, 22, 19 };
int* ptr = minimart(array, &array[2]); ptr[1] = 9; ptr += 2; *ptr = -1; *(array+1) = 79;
cout << "diff=" << &array[5] - ptr << endl;
swap1(&array[0], &array[1]); swap2(array, &array[2]);
for (int i = 0; i < 6; i++) cout << array[i] << endl;
return( 0 ); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
