In this code snippet
char *s="abcde";
int n=sizeof(s)/sizeof(s[0]);
cout<<n;
s is a pointer. So sizeof( s ) is equal to the size of pointers in the system. In your system the size of a pointer is equal to 4. As the type of s[0] is char then its size equal to 1 and you get value 4.
In the second code snippet
char s[]="abc";
int n=sizeof(s)/sizeof(s[0]);
cout<<n;
s is an array. Its size is determined by the size of the initializer. As string literal "abc" has size equal to 4 because the terminating zero is also counted then the size of array s is 4. If you for example would write
char s[]="abcde";
int n=sizeof(s)/sizeof(s[0]);
cout<<n;
then the size of the string literal is equal to 6 and correspondingly the size of the array will be also equal to 6.
You could the same code rewrite the following way
char s[6]="abcde";
int n=sizeof(s)/sizeof(s[0]);
cout<<n;
If you write this code as
char s[10]="abcde";
int n=sizeof(s)/sizeof(s[0]);
cout<<n;
then the size of the array will be equal to 10 though the size of the string literal is equal to 6. All other elements of the array that have no initializer will be zero-initialized. That is the array would look as
[a][b][c][d][e]['\0']['\0']['\0']['\0']['\0']