You are asking for the size of a char*
which is 4 indeed, not the size of the buffer. The sizeof
operator can not return the size of a dynamically allocated buffer, only the size of static types and structs known at compile time.
More Related Contents:
- Logic behind sizeof operator [duplicate]
- How to find the ‘sizeof’ (a pointer pointing to an array)?
- Why isn’t the size of an array parameter the same as within main?
- C sizeof a passed array [duplicate]
- Are there machines, where sizeof(char) != 1, or at least CHAR_BIT > 8?
- Are there any platforms where pointers to different types have different sizes?
- Why does sizeof(x++) not increment x?
- Checking the size of an object in Objective-C
- What is guaranteed about the size of a function pointer?
- Is dereferencing null pointer valid in sizeof operation [duplicate]
- Behavior of sizeof on variable length arrays (C only)
- What does sizeof without () do? [duplicate]
- How can I find the number of elements in an array?
- How sizeof(array) works at runtime?
- How to get the string size in bytes?
- Getting the size of a malloc only with the returned pointer
- C – SizeOf Pointers
- C pointers and arrays/ ‘sizeof’ operator [duplicate]
- Sizeof arrays and pointers
- Why (and when) do I need to use parentheses after sizeof?
- How to find the size of an array (from a pointer pointing to the first element array)?
- Sizeof vs Strlen
- Access struct members as if they are a single array?
- Is there any reason not to use fixed width integer types (e.g. uint8_t)?
- ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=] [duplicate]
- why sizeof(‘a’) is 4 in C? [duplicate]
- What decides the sizeof an integer?
- C -> sizeof string is always 8
- Size of pid_t, uid_t, gid_t on Linux
- Find size of array without using sizeof