Archived

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

Ekim_Gram

N00b question: What is char*?

Recommended Posts

CoffeeMug    852
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
smart_idiot    1298
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
smart_idiot    1298
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
VowOfSilence    122
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