tags:

views:

59

answers:

1
char name[10]="James";  //valid statement

char name[10];
strcpy(name,"james");   //valid statement

char name[10];
name[10]="james";       //invalid statement
*name="james";          // invalid statement

For above mentioned both invalid statment it says "error: assignment makes integer from pointer without a cast"

The error message is not clear. What is integer here? Which pointer is getting converted to integer.

char name[10];
name="james";   //invalid statement

error: incompatible types when assigning to type char[10] from type char

Please explain the error message to me. What exactly they ment.

+2  A: 

The problem is here:

name[10]="james";

name[10] in this context is a char (which is a type of integer), while "james" is a pointer (to char). So you're trying to convert a pointer to a char, which is an invalid conversion.

Note that when you write:

char name[10]; you're defining a char array of size 10.

When you write just:

name[10]

you're referring to element index 10 of name, i.e. the 11th char in name (which is actually out of bounds - the valid char indices in name are name[0]..name[9]).

Paul R
To be more specific, `name[10]` is "the eleventh character of `name`".
Borealid
what about the following errorerror: incompatible types when assigning to type char[10] from type char
"name[10] in this context is a char (which is a type of integer)"- not clear how this is an integer. Do you mean to say ASCII value has been considered here?
@user427394: a char is just one type of integer - it happens to be an 8 bit integer typically, and this can be interpreted as a character value if you choose to, but fundamentally it is just an integer.
Paul R
Thanks for your reply. It made the thing clear to me.