Can someone tell me how this compiles. How can you assign an integer array element to a pointer array element? The weird this is that the output suggests that nums[i] is an integer rather than a pointer, however nums was defined as a pointer.
#include <iostream>
int main() {
int n;
int *nums = NULL;
nums = new int[n]; // Assign pointer nums to a address in heap allocated for a integer array of n-elements.
n=5;
int Array[n] = {5,4,3,6,8};
for(int i=0; i<n; i++)
{
nums [i] = Array[i];
std::cout << nums[i] << " , " << &nums[i] << std::endl;
}
delete []nums;
return 0;}
I get the following output:
5 , 0x786cd0
4 , 0x786cd4
3 , 0x786cd8
6 , 0x786cdc
8 , 0x786ce0
Thanks for any help