Hi,
I wrote the following code:
Now I'm wondering why I need the statement last--; to get the last char. Shouldn't the for loop stop before reaching '\0'?Code:#include <stdio.h> int main(void) { char str[100] = "Hello world"; char *last; for(last = str; (*last) != '\0'; last++) ; last--; printf("last char: %c\n", *last); return 0; }
I was thinking the same program as above but leaving out the last--; would give us output: 'd'.