HOME       >>       Programming

For Question (Init; Cond; Incre)


Tran-Gate

// 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!!


Nabb

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.



VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.