Jump to content
  • Advertisement
Sign in to follow this  
Calin

char array null terminator

This topic is 3465 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Who's the inventor/what's the meaning? [Edited by - Calin on April 22, 2009 3:34:47 AM]

Share this post


Link to post
Share on other sites
Advertisement
I don't know who invented it, but at least in C/C++ when you have a string contained in an array of char you won't be able to tell where the string ends, you could argue that you know the array length but the string could be shorter, so the idea of the '\0' character is to tell where that happens in the array.

example:

char s[10]:

s[0]='\\';
s[1]='0';
s[2]='\0';
s[3]='x'; // won't be printed

printf("%s",s); // will print: \0

Share this post


Link to post
Share on other sites
Quote:
Original post by CalinIs this C++ char?


A C++ char array.
In general you'll find that people says that arrays are evil, cause they don't check you're writting in they space an many other reasons, they are telling you to use a higher-level type such as std::string instead of char[].

Share this post


Link to post
Share on other sites
I was wandering if that's what he's talking about.
Quote:
they don't check you're writting in they space
rephrase please

Share this post


Link to post
Share on other sites
Quote:
Original post by Calin
I was wandering if that's what he's talking about.
Quote:
they don't check you're writting in they space
rephrase please


Some compilers lets you go with this:

char s[10];
s[12] = 'x';

where you're writting beyond the space of memory assigned to the array, that can cause the program to crash or corrupt some data, maybe nothing happens, that depends on what was previously on that space.

EDIT: for further information about why array are 'evil' check this page:
http://www.parashift.com/c++-faq-lite/containers.html#faq-34.1

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!