Results 1 to 3 of 3

Thread: What does the * mean?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    What is the difference between int pVal and int *pVal?

    Also, I have seen the * directly after the type as well:

    char* blaba and char *blabla..

    I'm running into the following problem:

    error C2440: '=' : cannot convert from 'long' to 'long *'

    I have global variables defined as int pVal. I'm trying to assign that to another variable define as int *pValNew but I get the above error..

    Any ideas?

    Thanks,

    Dan


    Visual Studio 2010

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    In the context you're describing, * is the indirection operator, used for pointers. If you're used to VB and haven't come across pointers before then it's a common source of confusion.

    int *pVal

    This is declaring a pointer to an integer. This could be written as int* pVal or int * pVal and it would be the same thing.

    The value stored in pVal is the address of an integer variable somewhere in memory. The expression *pVal evaluates to the value of the integer that pVal contains the address of - the value that pVal points to.

    Pointers are useful in all kinds of situations, and you can have pointers to all kinds of different data structures, and even pointers to functions. I'd advise you to look it up in a book or something, as it would undoubtedly explain it better than I can.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width