I have an array of strings arr[5][8] = {...}
(every string was declared) and I am trying to understand what value of arr[3] - arr[2]
is and what is its type. I cannot understand why a difference between addresses are considered in bytes, because when I print this: printf("%d\n" , names[2] - names[1])
I get 8
.
Why does it behaves like this? A full code example below:
#include <stdio.h>
int main()
{
char names[5][8] = { "Miri", "Tali", "Ronit", "Avigail", "Shlomit" };
printf("%d\n", names[2] - names[1]);
system("pause");
return 0;
}
The output is 8
.
8
is exactly the distance from names[1]
to names[2]
in bytes (there are 8 chars in every string, every char is 1 byte). But I put %d
and thought that this distance will be printed in the decimal representation of these bytes. In other words, I thought the result to be 8*255
, because the max value that can be represented in 1 byte is 255 and here I have 8 bytes (char
s).