+ 6
Could someone clarify this for me?
C++ code by Waterfall St: char *s = "string\0"; int i = 1; while (*(++s)) ++i; If anyone could please explain (in simple terms) what the while condition means (and results in), I'd appreciate it!
2 Respuestas
+ 6
You have declared a char type pointer. Such a pointer points to the base address of the char array. Here, the base address points to 's'
By *(++s) you are pointing to the next value in the array, that is, 't'.
This continues till the loop reaches \0 where it terminates. If you had a cout <<i; at the end of the program, it would say 6, because i=1 and 6 is length of the array, so the loop runs 6 times.
+ 2
Here, the while statement means until the pointer 's' does not reach at the end of the word(so that ++S is not possible).