string

Hello every body..
I try to understand the execution of this code what happened exactly inside (I put cout in many places...) but I didn't understand. someone can explain me what happened inside the loop for in the void mystere..
thx a lot..

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <stdio.h>
#include<string.h>
using namespace std;
void mystere(char* s)
{
char c, *p;
for (p = s + strlen(s) - 1; s < p; s++, p--)
{
cout << "p= " << p << " s= " << s;
c = *s;
cout << " c= " << c;
*s = *p;
cout << " s= " << s;
*p = c;
cout << " p= " <<p;
cout << endl;
}
}
int main()
{

char ch[] = "BONJOUR";
mystere(ch);
printf("%s", ch);

return 0;
}
/*
Execution
p= R s= BONJOUR c= B s= RONJOUR p= B
p= UB s= ONJOUB c= O s= UNJOUB p= OB
p= OOB s= NJOOB c= N s= OJOOB p= NOB
RUOJNOB


*/
Topic archived. No new replies allowed.