Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: What does the asteriks mean?

Reply
Thread Tools

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>
>
> char answer[100], *p;
> printf("Type something:\n");
> fgets(answer, sizeof answer, stdin);
> if((p = strchr(answer, '\n')) != NULL)
> *p = '\0';
> printf("You typed \"%s\"\n", answer);
>
> ========
>
> The code is from the C FAQ located at the following URL:
> http://www.eskimo.com/~scs/C-faq/q7.1.html

 
Reply With Quote
 
 
 
 
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"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The modem for Asteriks Antonio VOIP 4 05-20-2004 05:46 PM
Asteriks! What i need? Antonio VOIP 2 05-14-2004 06:47 AM
Re: What does the asteriks mean? FakeAddress@NoSpam.com C Programming 5 06-26-2003 10:13 PM
Re: What does the asteriks mean? Dan Pop C Programming 0 06-26-2003 12:57 PM
Re: What does the asteriks mean? Tom St Denis C Programming 1 06-26-2003 01:43 AM



Advertisments