To get the size of the pointer use
printf("%d\n", (int) sizeof(record.name_pointer));
Your might get 2, 4, 6, 8, etc.
To get the size of the data that is pointed to by the pointer (a char
) use
printf("%d\n", (int) sizeof(*record.name_pointer));
Your should get 1.
To get the string length of the string pointed to by the pointer, assuming record.name_pointer
points to legitimate data, use
printf("%d\n", (int) strlen(record.name_pointer));
BTW As @alk says and why the (int)
casting above, a suitable conversion specifier to use with sizeof()
includes the 'z' prefix. The result of sizeof()
and strlen()
is of type size_t
. Although size_t
and int
are often the same, there are many systems where they are of different sizes. And since sizeof() is an "unsigned integer type" (C11 6.5.3.4), I recommend
printf("%zu\n", sizeof(...