开发者

What is the meaning of new int[25,2]?

What is the meaning of using the second parameter with a comma in the below code?

开发者_StackOverflow中文版
int *num = new int[25,2];


That's the comma operator in action: it evaluates it's operand and returns the last one, in your case 2. So that is equivalent with:

int *num = new int[2];

It's probably safe to say that the 25,2 part was not what was intended, unless it's a trick question.

Edit: thank you Didier Trosset.


That's the comma operator in action: it evaluates it's operand and returns the last one, in your case 2. So that is equivalent with:

int *num = new int[2];


You are using the comma operator, which is making the code do something that you might not expect at a first glance.

The comma operator evaluates the LHS operand then evaluates and returns the RHS operand. So in the case of 25, 2 it will evaluate 25 (doing nothing) then evaluate and return 2, so that line of code is equivalent to:

int *num = new int[2];


// Declare a single-dimensional array
int[] array1 = new int[5];

    // Declare and set array element values 
    int[] array2 = new int[] { 1, 3, 5, 7, 9 };

    // Alternative syntax 
    int[] array3 = { 1, 2, 3, 4, 5, 6 };

    // Declare a two dimensional array 
    int[,] multiDimensionalArray1 = new int[2, 3];

    // Declare and set array element values 
    int[,] multiDimensionalArray2 = { { 1, 2, 3 }, { 4, 5, 6 } };

    // Declare a  array 
    int[][] Array = new int[6][];

    // Set the values of the first array in the  array structure
    Array[0] = new int[4] { 1, 2, 3, 4 };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜