#include <iostream> using std::cout; using std::cin; using std::endl; #include <iomanip> int main() { const int arraysize=6; int i=0; char a[6]; cout<<"Enter "<<arraysize<<" letters: "; cin>>a[i]; for(i=0; a[i]; i++) { for (i=0; a[i]; i--); } return 0; }
Reversing order
Started by
Legally_Insane
, Nov 13 2005 04:12 PM
#1
Posted 13 November 2005 - 04:12 PM
#2
Posted 13 November 2005 - 06:35 PM
It doesn't *do* anything. You haven't TOLD it to do anything. Look at this:
for(i=0; a[i]; i++)
{
for (i=0; a[i]; i--);
}
First of all, that loop is dangerous because you are in essence asking the compiler to dereference memory outside of what you have allocated (the 6 characters). If the memory after a[6] is not null (zero), then this loop will never terminate.
Second, you don't tell it to do anything once it is looping.....
for(i=0; a[i]; i++)
{
for (i=0; a[i]; i--);
}
First of all, that loop is dangerous because you are in essence asking the compiler to dereference memory outside of what you have allocated (the 6 characters). If the memory after a[6] is not null (zero), then this loop will never terminate.
Second, you don't tell it to do anything once it is looping.....
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users