CrazyEngineers
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Kaustubh Katdare

    AdministratorMar 18, 2014

    I guess because it includes the null at the end; the terminating \0. By the way the correct way to get the length of string would be strlen() and not sizeof(); because sizeof will return the length of the array, not the string.

    C/C++ experts may offer better help.

    PS: Been away from programming since eternity.
    Are you sure? This action cannot be undone.
    Cancel
  • Jason Estibeiro

    MemberMar 18, 2014

    The sizeof() function provides the size of the data type in bytes. The character array consist of a terminating character '\0' (hence name[5]='\0') (as told by #-Link-Snipped-# ) and since each char value occupies a space of one byte, hence the result is 6 ... 6 bytes.

    And again as #-Link-Snipped-# said, if you want the length of the string use strlen() function. Then you would get the answer as 5.
    Are you sure? This action cannot be undone.
    Cancel
  • Shailaja Tiwari

    MemberMar 18, 2014

    Yes it is the null character assumed to be appended at the end of the string ....
    Are you sure? This action cannot be undone.
    Cancel
  • Aadit Kapoor

    MemberMar 18, 2014

    Thank you friends!
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register