#include <stdio.h>
int main(){
char Str1[] = "Hello World";
char Str2[12] = "Hello World";
char *Str3 = "Hello World";
char Str4[] = {'H','e','l','l','o',' ','W','o','r','l','d'};
printf("%s\n",Str4);
printf("Sizeof Str1 : %d \t Strlen Str1 : %d\n",sizeof(Str1),strlen(Str1));
printf("Sizeof Str2 : %d \t Strlen Str2 : %d\n",sizeof(Str2),strlen(Str2));
printf("Sizeof Str3 : %d \t Strlen Str3 : %d\n",sizeof(Str3),strlen(Str3));
printf("Sizeof Str4 : %d \t Strlen Str4 : %d\n",sizeof(Str4),strlen(Str4));
}
Output :
Hello World
Sizeof Str1 : 12 Strlen Str1 : 11
Sizeof Str2 : 12 Strlen Str2 : 11
Sizeof Str3 : 8 Strlen Str3 : 11
Sizeof Str4 : 11 Strlen Str4 : 11
You will Not get any Error that's correct But, If you see the String4 sizeof(Str4). i.e 11 which means the compiler is not adding the '\0' in Str4.
Sizeof (Str3) is 8 because its pointer type variable (i.e Sizeof(pointer) = 8 Byte
For all remaining String from Str1, Str2, Str3 the compiler Implicit added the '\0'