I am new to these pointers concept. I would like to know why doesn't the code below swaps both the string (or) atleast the first letter of the string.
Program:
#include<stdio.h>
void swap(char* s1,char* s2)
{
char* temp=s1;
s1=s2;
s2=*temp;
}
int main()
{
char* str1="Hello";
char* str2="Guys";
swap(str1,str2);
printf("%s\n%s\n",str1,str2);
return 0;
}
The output of the code remains the same string stored for that variable str1 and str2.
Output:
Hello
Guys
Here what I wanted to know is that as we are passing both the string to the function why doesn't the swap takes place. As address are swapped within the function why does the output doesn't gets swapped?...Why does the main function posses the same string in their respective variables(i:e str1 and str2)