#include <stdio.h>
#include <string.h>
typedef unsigned char *byte_pointer;
void show_bytes(byte_pointer start, size_t len)
{
size_t i;
for (i = 0; i < len; i ++)
{
printf("%.2x", start[i]);
}
printf("\n");
}
void show_int(int x)
{
show_bytes((byte_pointer) &x, sizeof(int));
}
int main()
{
const char *s = "abcdef";
printf("%ld\n", sizeof(s));
printf("%ld\n", strlen(s));
show_bytes((byte_pointer)s, sizeof(s));
show_bytes((byte_pointer)s, strlen(s));
return 0;
}
The output is :
8
6
6162636465660025
616263646566
Why are there two more bytes? Shouldn't there be just one more ending null?
Can someone tell me what the last byte of the sizeof
output represents?