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)?
In the
name = tempassignment, the value ofnameis converted to a pointer tochar. 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.