Question: in C prt-arg-2.c contains an implementation of a function swapIntegers, which swaps the values of two integers using their addresses (i.e. using pointers to the
in C
prt-arg-2.c contains an implementation of a function swapIntegers, which swaps the values of two integers using their addresses (i.e. using pointers to the integer data). Add and test a function swapStrings that will swap two strings.
DO NOT use strcpy. The characters comprising the strings do not need to be moved or changed in any way. Instead, the addresses pointed to by the string variables should be swapped.
#includevoid swapIntegers(int *, int *); int main(void) { int num1 = 5, num2 = 10; printf("Before the swap: num1 = %d and num2 = %d ", num1, num2); swapIntegers(&num1, &num2); printf("After the swap: num1 = %d and num2 = %d ", num1, num2); return 0; } void swapIntegers(int *n1, int *n2) { /* passed and returned by using values of pointers */ int temp; temp = *n1; *n1 = *n2; *n2 = temp; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
