c++ - Reverse char array using pointers -


can't understand what's going on in while if possible visualize, please.

int main()  {          char text[] = "hello";         int nchars = sizeof(text)-1;          char *pstart = text;         char *pend = text + nchars - 1;          //can't understand part          while (pstart < pend)         {             char tmp = *pstart;             *pstart = *pend;             *pend = tmp;              pstart++;             pend--;         }          cout << text << endl;          return 0; } 

it simple swapping mechanism. inside while loop code swapping values. see attached picture.

inside while loop swapping happening


Comments