write a c program for swapping two strings using pointer



write a c program for swapping two strings using pointer..

Answer / Hitesh Kumar Gupta

Here's an example C code for your request:

```
#include <stdio.h>

void swapStrings(char *str1, char *str2) {
char temp[100];
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
}

int main() {
char str1[100] = "Hello";
char str2[100] = "World";
printf("Before swap: %s and %sn", str1, str2);
swapStrings(str1, str2);
printf("After swap: %s and %sn", str1, str2);
return 0;
}
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

a linear linked list such that the link field of its last node points to the first node instead of containing NULL a) linked list b) circular linked list c) sequential linked list d) none

0 Answers  


Function calling procedures? and their differences? Why should one go for Call by Reference?

1 Answers   ADP,


Diff between for loop and while loop?

2 Answers   TCS,


What is the Difference between Macro and ordinary definition?

3 Answers   Bosch, Cognizant, College School Exams Tests, Motorola,


main(){char *str;scanf("%s",str);printf("%s",str); }The error in the above program is: a) Variable 'str' is not initialised b) Format control for a string is not %s c) Parameter to scanf is passed by value. It should be an address d) none

1 Answers  


when i declare as: void main() { clrscr(); int a=10; printf("%d",a) } my problem that why generate a error in above programs. please tell me answer seriously .

4 Answers  


How do you determine whether to use a stream function or a low-level function?

1 Answers  


If the static variable is declared as global, will it be same as extern?

1 Answers   Samsung,


What is the correct declaration of main?

1 Answers  


question-how to run a c programme.

6 Answers  


write a program whose output will be- 1 12 123 1234

10 Answers  


What is the use of getchar() function?

1 Answers  


Categories