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

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

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -