Question: complete the code to left rotate four integers by one position. Function rotate_4() takes four integer pointers as parameters and returns nothing. This is a

complete the code to left rotate four integers by one position. Function rotate_4() takes four integer pointers as parameters and returns nothing. This is a classic example of how pass-by-reference is more efficient in updating a batch of variables. Think about it: if you are not allowed to use pointers, how can you implement it?

Some example outputs follow:

% ./rotate 1 2 3 4

2 3 4 1

% ./rotate 1 2 3

Error: rotate needs four numbers

#include #include

void rotate_4(int *p_a, int*p_b, int*p_c, int* p_d) { //TO-DO: please implement left rotate 4 integers by one position }

int main(int argc, char ** argv) { //TO-DO check if there are 4 inputs. //print out an error message if there are not enough inputs. //hint: use argc int a = atoi(argv[1]); //atoi converts string to int int b = atoi(argv[2]); int c = atoi(argv[3]); int d = atoi(argv[4]); rotate_4(&a, &b, &c, &d); printf("%d %d %d %d ", a, b, c, d); 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!