I like to use this piece of code when I want to reverse a string. [When I am not using std::string
or other inbuilt functions in C
]. As a beginner when I initially thought of this I had ASCII
table in mind. I think this can work well with Unicode
too. I assumed since the difference in values (ASCII etc) is fixed, so it works.
Are there any character encodings in which this code may not work?
char a[11],t;
int len,i;
strcpy(a,"Particl");
printf("%s\n",a);
len = strlen(a);
for(i=0;i<(len/2);i++)
{
a[i] += a[len-1-i];
a[len-1-i] = a[i] - a[len-1-i];
a[i] -= a[len-1-i];
}
printf("%s\n",a);
Update:
This link is informative in association with this question.