Ad
  • Default User Avatar

    "sizeof" works at compile time, and returns the size of the type you're referring to. Using "sizeof" with a string only works if the string is stack allocated: char example[45] = "this is an example.", using "sizeof" here would return 45, rather than the actual length of the string. "strlen" counts the number of characters passed until it reaches the NULL byte. So "strlen" can be used on dynamically or stack allocated strings and return the correct size.