I want to know from where the index of a string and an array starts from. I am getting a lot of confusion while making programs.
While calculating string length of a string is the null character also counted?
I want to know from where the index of a string and an array starts from. I am getting a lot of confusion while making programs.
While calculating string length of a string is the null character also counted?
Not entirely clear what you're asking.
If you're asking whether strings and arrays start at index 0, then Yes.
In C, C++, Java, and Python, array indices are 0-based, so they range from 0 to length-1. Some mathematically-oriented programming languages such as Matlab are 1-based. As a general rule of thumb, "real programming languages" tend to use 0-based indexing; mathematical/protoyping/modeling languages or other domain-specific languages may use 0-based or 1-based indexing, with 1-based common for math.
In terms of strings, the length of a string usually refers to the number of characters in the string excluding the terminating NUL-character, while the length of the buffer refers to the entire buffer's length, including the terminating NUL. You will find that std::string::size() and strlen() return the number of characters in the string, excluding the terminating NUL (i.e. the string length). The length of the buffer is actually one more than that.