I am trying to create a char array dynamically. However, do not matter which number I put as the desired value of the size array it just keep using 4 has the size. If I place 3,2 or even 8, 10 it does not change…
Part where I initialize it…
char *x;
x = (char *)calloc(10, sizeof(char));
if(x == NULL )
{
return;
}
cout <<"Size_Vector = "<<sizeof(x)<<endl; //Keep making the size of the array 4..no matter what
sizeof(x)returns the size of the pointer not the allocated memory or the size of array.It always returns
4size of an pointer on your envrionment is4and it will be the same for all.You will have to keep track of how much memory you allocated yourself & also ensure that you do not write beyond the bounds of that allocated memory.