The java code below is well functioning code where I did was;
I used nums.length as the size for the declaring the new arrary within the function body.
If I am trying to do the same thing on c++ platform it doesn't work. Most of the time while creating array in c++ needs the constant size of the array.
So I need the reasonable solution which declare the new array within the function which will have the size of the array passed through the function as parameter.
eg.
I used nums.length as the size for the declaring the new arrary within the function body.
Code:
public int[] reverse3(int[] nums)
{
int[] temp = new int[[B]nums.length[/B]];
for(int i=0;i<nums.length;i++)
{
temp[i] = nums[nums.length-(i+1)];
}
return temp;
}
So I need the reasonable solution which declare the new array within the function which will have the size of the array passed through the function as parameter.
eg.
Code:
function(int a[],int [B]len[/B])
{
int arr[[B]len[/B]];
//while compiling this code will give error because size of arr should be constant as error comment of the compiler
}
Comment