Question
C PROGRAM help Add and test a function swapStrings that will swap two strings. DO NOT use strcpy . The characters comprising the strings do
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.
#include
void 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
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