Difference between char* and char[] in C

arrays, c, pointers

Solution

"Array name is a pointer to first element(here char pointer ..right?). right?"

char name[31];
char *temp;
/* ... */
name = temp;

In the `name = temp` assignment, the value of `name` is converted to a pointer to `char`. The value is converted, not the object. The object is still an array and arrays are not modifiable lvalues. As the constraints of the assignment operand require the left operand of the assignment operator to be a modifiable lvalue, you got an error.

Problem

Possible Duplicate: C - Difference between “char var[]” and “char *var”? I have written the following C code ``` #include<stdio.h> int main() { char name[31]; char *temp; int i ; scanf("%s",name); temp = name; name = temp; } ``` I got the following error when compiling ``` incompatible types when assigning to type 'char[31]' from type 'char *' ``` Array `name` is a pointer to first element(here char pointer ..right?). right? The above code means that character array and `char*` are different types ..Is it true? Why is the type of `name != char *`? Why can I assign another `char` pointer to a `char` pointer (the `name` array)?

Original source

Related problems