Original Post
So I had to take a test in c++ today and part of the test was writing a program that would reverse a string. I had no idea what I was going to do when I started out, but soon enough I started typing and came up with something. The problem is, I have no idea how the program works and would like some kind of an explanation. The program really isn't that complicated. Here it is: Thanks!
#include <iostream>
#include <ctype.h>
using namespace std;
int main()
{
//declare the array and counters
char array[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int counter,elements,letters;
//display the original array
cout << array << endl;
//get the string length of the array and set elements equal to letters
letters = strlen(array);
elements = letters;
//make a loop that uses each element of the array
for(counter=0;counter <= letters-1;counter++)
{
//confused here?
array[counter] = array[counter] + (elements - 1);
elements = elements - 2;
}
//display the reversed array
cout << array << endl;
return(0);
}