Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Needs to be written in C For this recitation assignment, complete the following tasks. You may receive guidance from your TA or fellow students. Declare
Needs to be written in C
For 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 user's 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 user's 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 = -4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started