#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;
}
我認爲它不工作的原因是因爲沒有所謂的變量 「a」,實際上存儲一個char *值。所以'a'應該被認爲是一個右值?我不知道如果我理解正確的概念
一個命名對象總是一個左值。 –
數組不是指針,但你似乎試圖使用它。 – chris
有這些東西(甚至更多)一個非常詳盡的解釋[這裏](http://stackoverflow.com/questions/4810664/how-do-i-use-arrays-in-c)。 –