I came across this
Code:
1. int strlen(char *s)
2. { char *p = s;
3.
4. while (*p != \0);
5. p++;
6. return p-s;
7. }
Questions:
1. In line 1, why the declaration of the *s is *s instead of s[]?
2. In line 2, why the initialisation of pointer p (*P) is assigned to s instead of *s? Since *p is to be filled with values and *s is a value and not 's' which is an address of pointer s.
3. In line 4, why there is a semicolon after the braces of while?
isnt it supposed to be
Code:
while (*p != \0)
{
p++;
}
return p-s;
4. This is a general question about pointer. If i declare a pointer as int *p, how many address will it increase if i type p+1? Will it be 1 or 4?
Thank you.