An array is not a pointer, although it can seem like one sometimes.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
// Empty brackets tell the array to calculate it's own size
// based on the number of elements in the initializer.
// A string literal includes a hidden '\0' at the end,
// so 'a' is auto-dimensioned to 27.
char a[] = "abcdefghijklmnopqrstuvwxyz";
// sizeof gives the size of the object in characters (bytes)
// which is just what we need for a malloc
char *p = malloc(sizeof a);
strcpy(p, a);
// The array is 27 bytes.
// strlen doesn't count the terminating '\0' char.
printf("[%s] %zu %zu\n", a, strlen(a), sizeof a);
// 64-bit pointers are 8-bytes.
printf("[%s] %zu %zu\n", p, strlen(p), sizeof p);
// In general, char arrays used as strings have a capacity
// and a currently-in-use size.
char b[100] = "abcdefg"; // capacity 99+'\0', current size: 7+'\0'
// The size of the string is determined by the current position of
// the first '\0' character. It is an error for string data to not
// have a '\0' character in the underlying char array.
// sizeof gives the size of the underlying array
printf("[%s] %zu %zu\n", b, strlen(b), sizeof b);
// although this size information is lost with a function call
// since the array variable b "decays" to a pointer when passed
// to a function. Size information needs to be passed separately.
void func(char*, size_t);
func(b, sizeof b / sizeof b[0]);
return 0;
}
void func(char *b, size_t size) {
printf("[%s] %zu %zu passed size: %zu\n", b, strlen(b), sizeof b, size);
}