Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ekim_Gram

N00b question: What is char*?

This topic is 5425 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

Advertisement
Type* VariableName; // where Type is int, float, char, whatever
By using the construct above you''re declaring a pointer to a type in memory. char* is basically a pointer to one (or more) characters in memory. It''s a fairly complex topic, I''m sure there are a lot of tutorials about pointers all over the net.

Share this post


Link to post
Share on other sites
char* is just a pointer to char which can be use to pass a string into a function, like so:

void SomeFunction( char* Str1 )
{
// Do something with Str1
}

Share this post


Link to post
Share on other sites
It means that somewhere in the tangle of data known as your computers memory, there is one byte of data representing a text (ASCII) character, possibly followed by more.

If you''re using it as a null terminated string, it is expected that following that first character is more characters, and one of them has a value of zero, which means ''Stop reading! This is the end of the string!''

Share this post


Link to post
Share on other sites
char * really is nice because
i can do somthing like this

char *asdf = "hi hi";
instead of lets say
char asdf[] = "hi hi"; its a pointer^^ i know that much lol
char * = LPTSTR

[edited by - DevLiquidKnight on August 14, 2003 2:52:50 AM]

Share this post


Link to post
Share on other sites
Think of the string as an array of characters, with an extra character at the end with a value of zero. Using a pointer for a string is like creating a dynamically allocated array in that sense.

Share this post


Link to post
Share on other sites
char* is a pointer to a location in memory. If you want to use it to store a string, make sure that you properly allocate memory for it.

You can declare it with

char *ptr = "hello, world\n";

or

char *ptr;
ptr = (char *) malloc(sizeofstring); // allocate memory

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!