I want to print out the capacity of my dynamic arrays, but no matter how I change it, it keeps saying that the capacity of both the arrays are 2.
The code (tmp.c)
#include <stdio.h>
#include <stdlib.h>
int main(){
int *ptr1 = (int *)malloc(sizeof(int) * 3);
int capacity_ptr1 = sizeof(ptr1)/sizeof(int);
printf("capacity of ptr1 is: %d\n", capacity_ptr1 );
int *ptr2 = (int *)realloc(ptr1, sizeof(int) * 5);
printf("capacity of ptr2 is: %ld\n", sizeof(ptr2)/sizeof(int) );
return 0;
}
What I execute in terminal
gcc -std=c99 tmp.c -o tmp
./tmp
The output in terminal
capacity of ptr1 is: 2
capacity of ptr2 is: 2
I get this output no matter what capacity parameter I enter for malloc() and realloc()