str = "Gate2015";
In memory
1000: G
1001: a
....
1007: 5
1008: \0
Now, str has the value 1000.
In the function, while loop terminates when P1 points to '\0' (which has integer value 0). So, P1 = 1008. And P1-P2 returns (1008-1000)/1 = 8 as size of char is 1 in C.