Here is an implementation.
You can also implement using function instead of macro, but function implementation cannot be done in C as C doesn’t support function overloading and sizeof() is supposed to receive parameters of all data types.
Note that above implementation assumes that size of character is one byte.
Time Complexity: O(1)
Space Complexity: O(1)
- Is sizeof for a struct equal to the sum of sizeof of each member?
- PHP | sizeof() Function
- Why does sizeof(x++) not increment x in C?
- sizeof operator in C
- Do not use sizeof for array parameters
- Anything written in sizeof() is never executed in C
- G-Fact 1 | (Sizeof is an operator)
- sizeof() for Floating Constant in C
- Operands for sizeof operator
- Result of sizeof operator
- How to find size of array in C/C++ without using sizeof ?
- Difference between strlen() and sizeof() for string in C
- How to implement Min Heap using STL?
- Implement your own itoa()
- Implement a Phone Directory