How to understand the pointer star * in C?

Jeffrey picture Jeffrey · Mar 30, 2011 · Viewed 72.1k times · Source

I'm struggling with the pointer sign *, I find it very confusing in how it's used in both declarations and expressions.

For example:

int *i; // i is a pointer to an int

But what is the logic behind the syntax? What does the * just before the i mean? Let's take the following example. Please correct me where I'm wrong:

char **s;
char *(*s); // added parentheses to highlight precedence

And this is where I lose track. The *s between the parantheses means: s is a pointer? But a pointer to what? And what does the * outside the parentheses mean: a pointer to what s is pointing?

So the meaning of this is: The pointer pointing to what s is pointing is a pointer to a char?

I'm at a loss. Is the * sign interpreted differently in declarations and expressions? If so, how is it interpreted differently? Where am I going wrong?

Answer

pradeepchhetri picture pradeepchhetri · Mar 30, 2011

Take it this way:

int *i means the value to which i points is an integer.

char **p means that p is a pointer which is itself a pointer to a char.enter image description here