Jump to content

Empty string: Difference between revisions

m
→‎{{header|C}}: spelling, formatting
(added ocaml)
m (→‎{{header|C}}: spelling, formatting)
Line 11:
[[Category:String manipulation]]
=={{header|C}}==
In C the strings are <code>char</code> pointers. A string terminates with the null char (U+0000, <code>'\0'</code>), which is not considered part of the string. Thus an empty string is <code>"\0"</code>, 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 equivelantlyequivalently 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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.