What is the meaning of using the second parameter with a comma in the below code?
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With