Your code doesn't do what you think it does.
char *str[2];char temp_str[10];str[0] = (char*)malloc(10*sizeof(char)); str[1] = (char*)malloc(10*sizeof(char));str[0] = "TEST 1";str[1] = "TEST 2";
The first four lines of this segment are fine. But then you get to the fifth line, str[0] = "TEST 1";. Now, str[0] is of type char*, and the string literal "TEST 1" is of type char[], so this statement functions as a pointer assignment, which puts the memory address of that string literal into str[0], leaking the memory you previously allocated. Note that string literals are stored in the program's code segment; this becomes important later.
Next, we get to the swap code:
strcpy(temp_str,str[0]); strcpy(str[0],str[1]); strcpy(str[1],temp_str);
Now the first line works just fine, because temp_str is an array of characters located on the stack. But then we get to the next line. As I mentioned above, the ill-formed string assignment has caused str[0] to point to a string literal in the code segment. On many platforms, the code segment is read-only by default, so when strcpy attempts to copy the data to the area pointed to by str[0], you get an error (such as a General Protection Fault of SIGSEGV).
The moral of the story is:
In C, strings are not a basic data type, so literals should never be assigned to variables using =. Use strcpy instead.EDIT: Darn, someone else said almost exactly the same thing while I was typing my response.