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)
- How to count set bits in a floating point number in C?
- Understanding “volatile” qualifier in C | Set 2 (Examples)
- How to change the output of printf() in main() ?
- Condition To Print “HelloWord”
- Implement your own itoa()
- Program to Find the Largest Number using Ternary Operator
- Passing Reference to a Pointer in C++
- How to avoid Structure Padding in C?
- wcrtomb() function in C/C++
- vswprintf() function in C/C++