cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
string
string
Mar 10, 2013 at 11:28pm UTC
klaus2013
(8)
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.