Honesty Rocks! truth rules.

For Question (Init; Cond; Incre)

HOME      >>       Programming


// Reverse case using array indexing. #include <iostream>#include <cctype> using namespace std; int main(){ int i; char str[80] = "This Is A Test"; cout << "Original string: " << str << "\n"; for(i = 0; str[i]; i++) { if(isupper(str[i])) str[i] = tolower(str[i]); else if(islower(str[i])) str[i] = toupper(str[i]); } cout << "Inverted-case string: " << str; return 0; }

In the for statement, how is the condition str?

I am confused!!


Thanks in advance!!


I don't know C++ specifically, but I'd assume that:

str returns the ith position in the string of str

str returns undefined for anything after 'This Is A Test'

undefined evaluates to false (i.e. breaks the loop), while any character (e.g. "i", "A") evaluates to true.