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 using namespace std; int* minimart(int* a, int* b) { if (*a < *b) return a; else return b; }

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!