09-4-2013, 11:18 PM
|
#10
|
new hand moves = dab
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
|
Re: Coding in C: help with if statements
Quote:
Originally Posted by MarioNintendo
I thought strings would work just like numbers. Really, why is there a difference?
|
Great question.
http://en.wikipedia.org/wiki/Null-terminated_string
Here's the pertinent information from that link:
Quote:
In computer programming, a null-terminated string is a character string stored as an array containing the characters and terminated with a null character ('\0', called NUL in ASCII).
|
Quote:
At the time C (and the languages that it was derived from) was developed, memory was extremely limited, so using only one byte of overhead to store the length of a string was attractive. The only popular alternative at that time, usually called a "Pascal string" (though also used by early versions of BASIC), used a leading byte to store the length of the string. This allows the string to contain NUL and made finding the length need only one memory access (O(1) (constant) time). However, C designer Dennis Ritchie chose to follow the convention of NUL-termination, already established in BCPL,
Quote:
to avoid the limitation on the length of a string caused by holding the count in an 8- or 9-bit slot, and partly because maintaining the count seemed, in our experience, less convenient than using a terminator.
|
|
To put it very simply: that's how C works. Your idea would have worked in many other languages, although it's probably not in accordance with best practice.
Does anyone know where to find comprehensive documentation or help guides? We can post Wikipedia links all day, but that doesn't compare to something like the Python documentation.
|
|
|