287 char* and char[] are different types, but it's not immediately apparent in all cases. This is because arrays decay into pointers, meaning that if an expression of type char[] is provided.

The char type can only represent a single character. When you have a sequence of characters, they are piled next to each other in memory, and the location of the first character in that.

char *str; // allocate a space for char pointer on the stack str = "1234556"; // assign the address of the string literal "1234556" to str As @Oli Charlesworth commented, if you use a pointer to a constant.

Understanding the Context

char *str = "Test"; is a pointer to the literal (const) string "Test". The main difference between them is that the first is an array and the other one is a pointer. The array owns its contents,.

I would like to understand how pointers work, so i created this small program. first of all i create a p pointer, which points to a char. The first question is at this point. If i create a pointe...

4 OK, I'll take a stab at this. The difference between char and char* is where the compiler puts the variable in memory that your using. char c is a stack declaration. The container holds the.

Technically, the char* is not an array, but a pointer to a char. Similarly, char** is a pointer to a char*. Making it a pointer to a pointer to a char. C and C++ both define arrays behind-the-scenes.

Key Insights

char *s = "hello"; So what is the difference? I want to know what actually happens in terms of storage duration, both at compile and run time.

the compiler should complain, because you're constructing an array of char arrays (or char pointers), and assigning it to an array of chars. Those types don't match up.

12 const char* x Here X is basically a character pointer which is pointing to a constant value char* const x is refer to character pointer which is constant, but the location it is pointing can.