Re: What does the asteriks mean?

Discussion in 'C Programming' started by sumit.sharma@wipro.com, Jul 8, 2003.

  1. Guest

    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


    wrote in message news:<>...
    > 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
     
    , Jul 8, 2003
    #1
    1. Advertising

  2. Just for the record, it's spelled (and pronounced) "asterisk".

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Jul 8, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom St Denis

    Re: What does the asteriks mean?

    Tom St Denis, Jun 26, 2003, in forum: C Programming
    Replies:
    1
    Views:
    818
  2. Re: What does the asteriks mean?

    , Jun 26, 2003, in forum: C Programming
    Replies:
    5
    Views:
    1,086
    Mark McIntyre
    Jun 26, 2003
  3. Dan Pop

    Re: What does the asteriks mean?

    Dan Pop, Jun 26, 2003, in forum: C Programming
    Replies:
    0
    Views:
    685
    Dan Pop
    Jun 26, 2003
  4. Li Ma
    Replies:
    1
    Views:
    2,368
    Roedy Green
    Mar 9, 2009
  5. C Barrington-Leigh
    Replies:
    1
    Views:
    1,286
    Tim Leslie
    Sep 10, 2010
Loading...

Share This Page