0

您能否解释一下这段 C++ 代码的作用:

int main()
{
    long * tempArray[10];
}

谢谢你的帮助!

4

3 回答 3

1

那个特定的代码片段根本没有任何作用。如果您编译该程序,它将终止并向宿主环境报告它已成功终止,仅此而已。

long * tempArray[10];声明了一个变量,称为具有指向 long 指针tempArray的类型数组 10 ,这意味着它能够容纳 10 个对象。tempArraylong *

出于演示目的:

// declare some long integers
long myLong = 100;
long anotherLong = 400;
long thirdLong = 2100;

// declare array 3 of pointer to long
long *tempArray[3];

// remember that arrays in C and C++ are 0-based, meaning index 0
// refers to the first object in an array. Here we are using the `&'
// operator to obtain a long pointer to each of the longs we declared
// and storing these long pointers in our array.
tempArray[0] = &myLong;
tempArray[1] = &anotherLong;
tempArray[2] = &thirdLong;
于 2012-07-23T03:50:00.547 回答
0

它创建一个包含 10 个长指针的数组。

于 2012-07-23T03:05:31.600 回答
0

代码实际上并没有做任何事情。

long * tempArray[10];分配一个能够保存十个指向长整数的指针的数组。

于 2012-07-23T03:06:36.100 回答