Array empty[] at Line 6 is created as an empty string. It has a single element, a null character. The length of this string is zero, though it has one element. Array null[] at Line 7 is a null string. The string is empty. But the string handling functions are particular with the strings and cannot deal with any of the non-string data provided. Hence to process non string data, usage of memory functions will be recommended. The integer constant, that is, zero has many different meanings depending on its usage.
In most cases, it will be an integer constant with the value 0 but will be described in other forms. We can check the NULL pointer in the following ways:. This pointer will point to an integer, but at the moment, it points to nothing. A string constant such as "some text" is a null-terminated string. So it is an array of characters, with a null character at the end. A string constant is not allowed to have an actual line break in it. But if you write two or more string constants in a row, they are automatically combined into a single string constant.
Combination of consecutive strings only works for string constants, not for other expressions that represent strings. So it takes time that is proportional to the length of the string.
Avoid computing strlen s over and over for the same string s in the same function. Function strcmp compares strings s and t for alphabetical ordering or for equality.
Alphabetical ordering is determined by character codes. Since 'Z' is 90 and 'a' is 97, Z comes before a in the alphabetical ordering used by strcmp.
Be careful. Connect and share knowledge within a single location that is structured and easy to search. The following code:. What is going on behind the scenes? Thus in the first two examples you start at the point offset of the 6th character in the string, but in your case you are printing out the 6th character which is t. It simply copies from it until it hits a null-terminator, then stops copying.
So your last example is actually invoking undefined behaviour; word2[6] goes past the end of the string. This means that the convention for C-strings apply. That's why word2 only contains "hello".
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
0コメント