Jump to content
xisto Community
Sign in to follow this  
Tran-Gate

For Question (Init; Cond; Incre)

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Edited by Nabb (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.