Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
String (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Null-terminated ==== {{Main|Null-terminated string}} The length of a string can be stored implicitly by using a special terminating character; often this is the [[null character]] (NUL), which has all bits zero, a convention used and perpetuated by the popular [[C (programming language)|C programming language]].<ref> {{Citation |last1 = Bryant |first1 = Randal E. |author-link = Randal Bryant |last2 = David |first2 = O'Hallaron |title = Computer Systems: A Programmer's Perspective |place = Upper Saddle River, NJ |publisher = Pearson Education |year = 2003 |edition = 2003 |url = http://csapp.cs.cmu.edu/ |isbn = 0-13-034074-X |page = 40 |url-status = live |archive-url = https://web.archive.org/web/20070806075942/http://csapp.cs.cmu.edu/ |archive-date = 2007-08-06 }} </ref> Hence, this representation is commonly referred to as a '''C string'''. This representation of an ''n''-character string takes ''n'' + 1 space (1 for the terminator), and is thus an [[implicit data structure]]. In terminated strings, the terminating code is not an allowable character in any string. Strings with ''length'' field do not have this limitation and can also store arbitrary [[binary data]]. An example of a ''null-terminated string'' stored in a 10-byte [[Buffer (computer science)|buffer]], along with its [[ASCII]] (or more modern [[UTF-8]]) representation as 8-bit [[hexadecimal number]]s is: {| class="wikitable" style="margin-left: auto; margin-right:auto" |- | <code>F</code> || <code>R</code> || <code>A</code> || <code>N</code> || <code>K</code> | <small>[[Null character|NUL]]</small> | style="background: #DDD" | <code style="background: #DDD">k</code> | style="background: #DDD" | <code style="background: #DDD">e</code> | style="background: #DDD" | <code style="background: #DDD">f</code> | style="background: #DDD" | <code style="background: #DDD">w</code> |- | 46<sub>[[Hexadecimal#Using 0β9 and AβF|16]]</sub> || 52<sub>16</sub> || 41<sub>16</sub> || 4E<sub>16</sub> || 4B<sub>16</sub> | 00<sub>16</sub> | style="background: #DDD" | 6B<sub>16</sub> | style="background: #DDD" | 65<sub>16</sub> | style="background: #DDD" | 66<sub>16</sub> | style="background: #DDD" | 77<sub>16</sub> |} The length of the string in the above example, "<code>FRANK</code>", is 5 characters, but it occupies 6 bytes. Characters after the terminator do not form part of the representation; they may be either part of other data or just garbage. (Strings of this form are sometimes called ''ASCIZ strings'', after the original [[assembly language]] directive used to declare them.)
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)