1. ## Size of pointer?

Well, I know sizeof(pointer) does not give me the size of the allocated space, but the size of the pointer itself. But there isn't a way to know it? Since if we use the free() function it will free the allocated space receiving only the pointer as argument. How's that?

2. > But there isn't a way to know it?

No standard way. Why? Because the committee decided it wasn't important enough, I suppose. That said, in the majority of cases you know the size that was allocated somewhere, and it's straightforward enough to pass around as needed.

3. > Since if we use the free() function it will free the allocated space receiving only the pointer as argument. How's that?
When you called malloc, the size of the block allocated is typically stored somewhere, so that free knows what to do.

Most programs are only interested in how many objects a pointer points to, not how many bytes.
Eg
Code:
```size_t num = 10;
int *mem = malloc( num * sizeof(*mem) );
for ( size_t i = 0 ; i < num ; i++ ) mem[i] = 0;```

I don't understand why it's not that important, but that's ok. It would be useful to me to know that, since in small programs I made I had to use 2 variables to store the size of the allocated space and the size of the using space in order to use realloc() whenever it's necessary

5. It's not that it wasn't deemed "important". It's that malloc shouldn't have to remember the exact size that you asked for. In order to manage and free the block, malloc only needs to remember the actual amount of memory that it set aside, which may be more than you asked for.

On linux, you could try the following, which returns 136 for me, even though I only asked for 123 bytes. Note that there is in fact a (non-standard) function to get the usuable block size.
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <malloc.h> // malloc_usable_size()

int main(void) {
char *p = malloc(123);
printf("%d\n", (int)malloc_usable_size(p));
free(p);
return 0;
}```

6. Originally Posted by Mortanius
I don't understand why it's not that important, but that's ok.
Let me try to explain.

First of all, think of C as a "close to the metal" language, meaning that, although "high level", it tries to be as fast, direct and low-on-resources as possible. Also, consider that C was initially created as a tool to build Unix with. Lastly, think of the myriad of devices( such as micro-controllers etc ) whose functionality has little resemblance to modern PCs.

With the above said, what would be the benefits of an automatic length/size associated with a pointer/array? Convenience maybe... But would it? I'll list some of the potential problems/concerns:
*) How many bytes should this length/size variable be?
*) Would it be optional? ( Yes: efficiency problem ) ( No: size problem )
*) Would it be enforced( not allowed to go out-of-bounds )?

These are my two cents on the subject.