我有如下所示的 C++ 代码:
static int* ArrayGenerator()
{
int temp[1] = {9};
return temp;
}
static int* ArrayGenerator(int i)
{
//parameter is just for demonstration
int temp[1] = {9};
return temp;
}
int _tmain(int argc, _TCHAR* argv[])
{
int arr1[1] = {9};
printf("arrays are %s equal\n\n", (memcmp(arr1, ArrayGenerator(), 1) == 0) ? "" : "not");
printf("arrays are %s equal\n\n", (memcmp(arr1, ArrayGenerator(1), 1) == 0) ? "" : "not");
}
第一个给我“平等”,第二个给我“不平等”。
为什么是这样?