Remember, that in C, opposed to C++, Java or other high level languages, there exists no string data type and most strings are just represented by arrays of characters. The variable name of an array is simply the pointer to the beginning of the array.
What you are doing in your example is actually subtracting the pointer to a
from the pointer to b
and then converting this resulting (pointer) value to an integer. Why the returned value is -16 I don't know. Probably this is just the size of memory blocks on the stack that are allocated at once (beware, pure speculation).
In order to subtract characters from each other, you have to really access them, either by using a[i]
or *(a+i)
for the ith character in the char array.
Fyi, the value of pointer subtraction is not random, but more or less arbitrary, since the addresses of the arrays a[]
and b[]
can differ from OS to OS and from compiler to compiler. I just tried your program on the PC I'm currently at, Debian Wheezy 64 bit, and the result is -16. Then I tried the same code on Xubuntu 12.04 32bit and the result is 5.