So I have this code in here I've try to create a 2-D array with different sizes,
first I declare 3 pointers then I assign different arrays to them and hope it works and it did well, but there is the problem , in the second code the compiler gives an error ( a value of type int*
cannot be assigned to an entity type int
) so it means they are no longer pointers I think , but why is that , what am I missing here ? what is the biggest difference in these two codes other than one of them is declared in stack and other is on the heap
int main()
{
int* arr[3];
arr[0] = new int[5];
arr[1] = new int[2];
arr[2] = new int[6];
delete[] arr[0];
delete[] arr[1];
delete[] arr[2];
}
//2nd Code
int main()
{
int* arr = new int[3];
arr[0] = new int[5];
arr[1] = new int[2];
arr[2] = new int[6];
}
and sorry for my baddd English