|
-
Jan 10th, 2001, 06:07 PM
#1
Thread Starter
Frenzied Member
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
-
Jan 10th, 2001, 06:16 PM
#2
Frenzied Member
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."
-
Jan 11th, 2001, 03:25 PM
#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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|