Pointers and string

char *a=“apple”;
cout<<a;
Why it prints apple please explain as a a pointer how it prints apple directly as also no char array and
char *a={‘a’,'p,‘p’,'l,‘e’}
Cout<<a;
Why it error

hey mayur, char *a={‘a’,'p,‘p’,'l,‘e’} this syntax is not valid because here you are allocationg different alphabets in an array and you are here trying to make a pointer which is not valid. in char *a=“apple”; this you are making a pointer “a” which is pointing to apple.
char a[5]={‘a’,'p,‘p’,'l,‘e’}; this will work here.

Is this apple store in stack or heap

Hey Mayur, String literals such as “apple” are stored in such a way that they are held over the lifetime of the program. They are often stored in a separate data segment (distinct from the stack or heap) which may be read-only.

For further more reference you can read this article to understand the concept.