Pointers program

Write a very simple program that uses two for loops and ONLY pointers and pointer arithmetic (NO other variables are allowed) to display a palindrome forward then backward. Declare the palindrome as follows:

char str[] = “Straw Warts”;


I just need help where to get started I'm having a tough time
this is what i got but i need two for loops
#include <iostream>

using namespace std;



int main()

{

char str[] = "Straw Warts";


for(char *ptr=str; *ptr!='\0' ; ptr++)

{

cout << *ptr;

}

char *ptr= str;

while(*ptr!='\0')

{

cout << *ptr++;

}

}

let me give you a hint...
the first for loop is to get the last posiotion of that array using pointers
and the second is to do the process...
so you will need 2 pointers
1
2
3
4
5
int *finalPosition;
int *count;

for(.........)//gets the final position of the array
for(.........;finalPosition--,count++)//carry out the function for some condition you can use the space to controll the loop.. 
Topic archived. No new replies allowed.