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?
- sizeof operator in C
- Why does sizeof(x++) not increment x in C?
- sizeof() for Floating Constant in C
- Do not use sizeof for array parameters
- Operands for sizeof operator
- Anything written in sizeof() is never executed in C
- How to find size of array in C/C++ without using sizeof ?
- Difference between strlen() and sizeof() for string in C
- Implement your own itoa()
- How to implement Min Heap using STL?
- Using class to implement Vector Quantities in C++
- Implement your own tail (Read last n lines of a huge file)
- Dividing a Large file into Separate Modules in C/C++, Java and Python