JacKeown
JacKeown

Reputation: 2890

What does char * mean

So...say I had a function like this...

int function( const char *c )
{
 //do something with the char *c here...
}

what does char *c mean? I know about chars in general I think but I don't get what the * does...or how it changes the meaning.

Upvotes: 5

Views: 36987

Answers (9)

sjr
sjr

Reputation: 9875

This is a pointer to a character. You might want to read up about pointers in C, there are about a bazillion pages out there to help you do that. For example, http://boredzo.org/pointers/.

Upvotes: 2

Todd Hopkinson
Todd Hopkinson

Reputation: 6883

It means that this is a pointer to data of type char.

Upvotes: 6

Pooh
Pooh

Reputation: 21

This is a pointer to a char type. For example, this function can take the address of a char and modify the char, or a copy of a pointer, which points to an string. Here's what I mean:

char c = 'a';
f( &c );

this passes the address of c so that the function will be able to change the c char.

char* str = "some string";
f( str );

This passes "some string" to f, but f cannot modify str.

It's a really basic thing for c++, that higher-level languages (such as Java or Python) don't have.

Upvotes: 1

deovrat singh
deovrat singh

Reputation: 1215

http://cslibrary.stanford.edu/ is the best resource that I have come across to learn about pointers in C . Read all the pointer related pdfs and also watch the binky pointer video.

Upvotes: 1

KV Prajapati
KV Prajapati

Reputation: 94635

You might want to read Const correctness page to get a good idea on pointer and const.

Upvotes: 1

spockaroo
spockaroo

Reputation: 188

char *c means that c is a pointer. The value that c points to is a character.

So you can say char a = *c.

const on the other hand in this example says that the value c points to cannot be changed. So you can say c = &a, but you cannot say *c = 'x'. If you want a const pointer to a const character you would have to say const char* const c.

Upvotes: 6

Sadique
Sadique

Reputation: 22823

Thats a pointer-to-char. Now that you know this, you should read this:

About character pointers in C

Upvotes: 2

splonk
splonk

Reputation: 1045

Pointer to a char. That is, it holds the address at which a char is located.

Upvotes: 2

alex
alex

Reputation: 490153

It means the argument should be a pointer to a character.

You would dereference it with * as well.

Upvotes: 1

Related Questions