c++ - Is pointer valid condition for a loop? -


can explain, why in case loop repeats 10 times?

#include <iostream> using namespace std; int main(){      int length=-1;     char s[]="bad or nice";//10 characters       ( char *q = s; *q; ++q ){     cout << *q;     length++;     }      cout << "\n" << length;  return 0; } 

the condition value @ memory location of pointer (*q).

therefore loop terminates when null character reached (at end of string), evaluated false.


Comments

Popular posts from this blog

rdbms - what exactly the undo information lives in oracle? -

bash - How do you programmatically add a bats test? -

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -