Code:
int mystrlen(const char *str)
{
int len = 0;
while (*str++)
len++;
return len;
}
void main() {
char *str1 = "Hello";
printf("\n length = %d \n", mystrlen(str1));
printf(" str=%s\n", str1);
}
o/p :
length = 5
str=Hello
Here in main function, we call mystrlen() and pass a reference address of str.
In function mystrlen(), we modify/increase(str++) the string pointer till '\0'.
In main() we print the str after function call mystrlen. But string will print whole contents. It will print hello. How is this possible? Because in mystrlen() the pointer pointing to NUL...