Well usually you can do something like:
Code:
int *ptrArray = NULL;
int nNumberOfInts = 20;
unsigned totalSize = nNumberOfInts * sizeof(int);
ptrArray = (int*) malloc(totalSize);
// ptrArray now points to a block of memory that is
// number of elements * the size of an int
// so
printf("Total size of block of %d integers should be: %d\n", nNumberOfInts, totalSize);
printf( "Or, sizeof(ptrArray[0] * nNumberOfInts = %d\n", sizeof(ptrArray[0]) * nNumberOfInts);
Output:
Code:
jeff@jeff-gate:~/dev/arraysize$ ./arraysize_test
arraysize_test 1.0
Testing: arraysize
Total size of block of 20 integers should be: 80
Or, sizeof(ptrArray[0] * nNumberOfInts = 80
jeff@jeff-gate:~/dev/arraysize$
Guess it works