Velocity Reviews > Re: What does the asteriks mean?

Re: What does the asteriks mean?

sumit.sharma@wipro.com
Guest
Posts: n/a

 07-08-2003
Hi,
The asterik before any variable declaration in program means a pointer
variable.

For eg.

int index; /* this is simple variable , which will hold a value */

Now,

int * pIndex; /* this is a pointer variable. */

Pointer variables do not hold normal values. Instead they point to
some
other variable. This means it should contain the address of that
another
variable.

With pointers, there are two frequently used operators.

1. the asterik operator (*). This is called as De referencing
operator. It dereferences the value pointed to by the pointer.

2. the address operator (&). This is used to make pointer point to
some variable of same type.

For eg;

/* These are simple variables */

int intVar = 10; /* integer variable */
float floatVar = 10.45; /* float variable */
char charVar = 'A'; /* char variable */

/* the following are pointers to above variables */

int * intPtr = &intVar; /* intPtr now points to intVar */
float * floatPtr = &floatVar; /* floatPtr now points to floatVar */
char * charPtr = &charVar; /* charPtr now points to charVar */

/* Print all values */

printf ("Integer variable = %d\tthrough pointer = %d\n", intVar,
*intPtr);
printf ("Float variable = %f\tthrough pointer = %f\n", floatVar,
*floatPtr);
printf ("Character variable = %c\tthrough pointer = %c\n", charVar,
*charPtr);

Moe on Pointers...refer K&R and Y P Kanetkar books on Pointers in C...

Sumit

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote in message news:<(E-Mail Removed)>. ..
> What does the * mean before the p in the following code? I figure
> that it has something to do with pointers, but I haven't learned about
> pointers yet.
>
> ========
>
> #include <stdio.h>
> #include <string.h>
>
> printf("Type something:\n");
> if((p = strchr(answer, '\n')) != NULL)
> *p = '\0';
>
> ========
>
> The code is from the C FAQ located at the following URL:
> http://www.eskimo.com/~scs/C-faq/q7.1.html

Keith Thompson
Guest
Posts: n/a

 07-08-2003
Just for the record, it's spelled (and pronounced) "asterisk".

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"