Difference between strlen() and sizeof() for string in C


Sizeof operator is a compile time unary operator which can be used to compute the size of its operand.

  • The result of sizeof is of unsigned integral type which is usually denoted by size_t.
  • sizeof can be applied to any data-type, including primitive types such as integer and floating-point types, pointer types, or compound datatypes such as Structure, union etc.


strlen() is a predefined function in C whose definition is contained in the header file “string.h”.