Why can you put multiple characters in C ++ char *

I can’t understand how this works.

// This doesn't work (obviously)
char a;
a = "aaa";

// This works
char* a;
a = "aaa";

How it works?

Since a type charstores only one character or 1 byte, how can you store more characters in it when accessing it through a pointer?

+4
source share
2 answers

You do not put characters in char*. You create an array of characters in the memory part defined by your compiler, and point char*to the first character of this array.

const, , const. ++. ++ 11 .

+8

- , char. .

+2

All Articles