#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char* buffer = malloc(1000*sizeof(char));
memset(buffer,'\0',1000);
printf("%ld\n",sizeof buffer); // Size of Pointer
printf("%ld\n",sizeof *buffer); // Size of Memory Block pointed at by buffer
printf("%ld\n",strlen(buffer)); // Length of String
return 0;
}
// Output:-
// 8
// 1
// 0
The code works fine.
The output is as expected, but how do I find the length of contiguous memory that I initialized with malloc if I don't know the length?