Empty string: Difference between revisions

m (Not sure what that was there for...)
Line 10:
 
[[Category:String manipulation]]
=={{header|C}}==
In C the strings are <code>char</code> pointers. A string terminates with null char '\0', which is not considered part of the string. Thus an empty string is "\0", while a null string is a null pointer which points to nothing.
<lang C>/* to test a null string */
if (str) { ... }
/* to test if string is empty */
if (str[0] == '\0') { ... }
/* or equivelantly use strlen function */
if (strlen(str) == 0) { ... }
/* or compare to a known empty string, same thing. "== 0" means strings are equal */
if (strcmp(str, "") == 0) { ... }
</lang>
=={{header|D}}==
D treats null strings and empty strings as equal on the value level, but different on object level. You
Anonymous user