Why is *str in the following fragment dereferenced only once? It takes the first character of the string 'a' and keeps incrementing this value until it reaches the end of the ASCII table, contrary to my expectation of dereferencing it on every condition evaluation and resulting in the infinite loop. This behavior does change even if the dereference is moved from the condition to the body of the loop. GCC version 7.4.0 was used to test the code.
int getLen(char *str){
int count=0;
while((*str)++) {
count++;
}
return count;
}
int main(){
char s[]="abc";
printf("length is %d\n",getLen(s));
}
Output: 159