Hi, i have the following program:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int *test, i;
int test2[5] = {1,2,3,4,5};
test = malloc(5*sizeof(int));
//populate dynamic array with arbitary data
for(i=0; i<5; i++){
test[i] = i+1;
printf("test[%d] = %d\n", i, test[i]);
}
//OUTPUT 1
printf("sizeof test = %d\n", sizeof(test));
//OUTPUT 2
printf("sizeof test2 = %d\n", sizeof(test2));
}
The OUTPUT 1 returns the size of test (the dynamically allocated array) to be 4 and OUTPUT 2 returns test2 as 20. Surely they should both be the same (ie 20) as they both hold 5 elements each. Or is there a different way for establiching the size of a dynamic array?
thanks i advance.
tg