so I have simple problem with dynamically allocated array of integers when counting 'em. Result is '1' always which is obvious because sizeof x is 4 and when divided by 4 = 1.
So is there way to get sizeof whole array?
1 2 3 4 5 6 7 8 9
#include<iostream>
usingnamespace std;
void main(void)
{
int *x=newint [];
*x=1;*(x+1)=2;*(x+2)=3;
int elm = (sizeof x)/(sizeof *(x+1));
}
And I know that this works when array is created like "int array[]" -- but since i'm learning want to try this way.
I do not know why the compiler allows you to write such construction. You should explicitly specify the number of elements of the array you are allocating.
Also this statement have no any sense because sizeof( int *) / sizeof( int ) is always usually equal to 1