Go straightforward, since C pass pointers as parameters to functions, why the program below the printf in swap function doesn't print the same address as the pinrtf in main function(I think the pointers were passed correctly), does something wrong here?
#include <stdio.h>
void swap(char **str1, char **str2)
{
char * temp = *str1;
*str1 = *str2;
*str2 = temp;
printf("1---(%#x) (%#x)---\n", &str1, &str2);
printf("2---(%s) (%s)---\n", *str1, *str2);
}
int main ()
{
char * str1 = "this is 1";
char * str2 = "this is 2";
// swap(&str1, &str2);
printf("(%s) (%s)\n", str1, str2);
printf("(%#x) (%#x)\n", &str1, &str2);
swap(&str1, &str2);
printf("(%s) (%s)\n", str1, str2);
printf("(%#x) (%#x)\n", &str1, &str2);
return 0;
}