Hi ahmed,
I try to explain it for you with help of a simple example,
suppose you enter your name,"ahmed"
so it stores in an array of chars
text[0]=a,text[1]=h,text[2]=m,text[3]=e,text[4]=d,text[5]='\0'
as you see in C++ the end of a string is defined as a '\0' character.
integer variable beg shows the beginning of the text(0),
integer variable back shows the end of the text(4),
integer variable l shows the length of the text(5),
now the algorithm starts to traverse from the beginning and the end of the text equally
Code:
while( (beg<=back) && flag )
{
if(text[beg] == text[back])
flag=1;
else
flag=0;
beg++;
back--;
}
beg++ back--
----> <----
a h m e d
in every loop beg increases one unit and back decreases one unit for checking the letters have the same distances from beginning and the end of the text.if there are two different letters the flag becomes 0 and your program exits from the loop cycle and tells you the text wasnt palindrome otherwise the flags remains 1 and the Conditional statement tell you the text was palindrome.
HtH.
--------------------------------------------
Mehdi.:)