Possible Duplicate:
Is array name a pointer in C?
#include <stdlib.h>
int main(int argc, const char *argv[])
{
char *b=(char*)malloc(sizeof(char)*50);
b=(char*)"hello world";
// works
char a[50];
a=(char*)"hello world";
//doesn't work. why? I thought array names are just pointers that point
//to the first element of the array (which is char). so isn't a char*?
return 0;
}
I think the reason it doesn’t work is because there’s no variable called “a” that actually stores a char* value. so should ‘a’ be considered an rvalue? I’m not sure if I’m understanding the concept correctly
Arrays are not pointers, sometimes[Note 1:] the name of an array decays to a pointer when array name is not valid(eg: passing to function).
Arrays are non modifiable l-values, they cannot be assigned and there address can be taken.
[Note 1:]
For example:
Array name doesn’t decay to a pointer when used in
sizeof()Array address cannot be changed but content can be changed.