PDA

Click to See Complete Forum and Search --> : What does the * mean?


softwareguy74
Jan 10th, 2001, 05:07 PM
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

HarryW
Jan 10th, 2001, 05:16 PM
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.

Jan 11th, 2001, 02:25 PM
http://www.itknowledge.com/reference/archive/0672310708/htm/ch08.htm