why when we build an array like this:
char st[]="abcd";
we have 5 cells in which the last cell is \0
why is that
and what are the number of each cell
is it from 0-4
or 1-5 ??
This is a discussion on what is the role of
Thread: what is the role of \0 place in an array..
place in an array.. within the C Programming forums, part of the General Programming Boards category; why when we build an array like this:
char st[]="abcd";
we have 5 cells in which the last cell is ...
what is the role of \0 place in an array..
why when we build an array like this:
char st[]="abcd";
we have 5 cells in which the last cell is \0
why is that
and what are the number of each cell
is it from 0-4
or 1-5 ??
Because at the lowest level, a string in C is just a sequence of characters. And since the length of the string isn't stored anywhere, you need a different way to tell where the end of the string is. So every string in C is terminated by a NULL character (\0), in most cases.
In your example,
char st[]="abcd";
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
so every array ends with \0 cell ??
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Just an example: strlen calculates the length of a string. It does this by checking every character in the array for '\0' and counts upwards. When it finds '\0', it can return the length.
よく聞くがいい!私は天才だからね! ^_^
thanks i understand now
Recent additions
Similar Threads
sorting number
array of pointers/pointer arithmetic
[question]Analyzing data in a two-dimensional array
Array Program
two dimensional dynamic array?