Laura Char Carson

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 sequence is returned (assigned to test). Test is nothing more than a pointer to the memory location of the first character in "testing", saying that the type it points to is a char.

laura char carson 1 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

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 where one of type char* is expected, the compiler automatically converts the array into a pointer to its first element.

laura char carson 2 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

What is the difference between char array and char pointer in C?

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, which happen to be a copy of "Test", while the pointer simply refers to the contents of the string (which in this case is immutable).

laura char carson 4 Exclusive Content Member Only — Sign Up Free 🔒 Unlock full images & premium access

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 as pointer types, so yes, this structure, in all likelihood, is array of arrays of char s, or an array of strings.

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.