1. Engineering
  2. Computer Science
  3. needs to be written in c...

Question: needs to be written in c...

Question details

Needs to be written in CFor this recitation assignment, complete the following tasks. You may receive guidance from your TA or fellow students. Declare an integer pointer and then request memory using malloc () for an array of 2 integers. This means that you should request memory for a size of 2 times the size of an integer and assign it to int_ptr. Use man 3 malloc for details on this system call. 1. 2. If the malloc ) system call failed to return memory, print out a meaningful error message and terminate the program. 3. Prompt the user to enter the first integer using printf and then read in the users response using scanf, storing the integer in the first element of the integer array allocated in step 1. 4. Prompt the user to enter the second integer using printf and then read in the users response using scanf, storing the integer in the second element of the integer array allocated in step 1 Now, print out the original values of both the integers input by the user. This next step is where the swapping is done: a. Use the bitwise XOR operator on both the array elements and assign the result to 5. 6. the first element. b. Use the bitwise XOR operator on both the array elements and assign the result to the second element. c. Use the bitwise XOR operatoron both the array elements and assign the result to the first element. Now, print out the swapped values of both the integers input by the user. Finally, release the allocated memory using free () 7. 8.

SAMPLE OUTPUT (user input shown in bold): $ . /a.out Enter first integer: 571 Enter second integer: 18 Original values: 1st571 2nd18 Swapped values: 1st 18 2nd571 $ ./a.out Enter first integer: -4 Enter second integer: 288 Original values: 1st 2nd288 Swapped values: 1st = 288 2nd = -4

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution