Ad
  • Default User Avatar

    it makes sens now.Thank you so much for this wonderfull explanation

  • 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.

  • Default User Avatar

    why you used strlen insteed of sizeof i didnt get it here? when we do sizeof we wont get the size of the string?