Click here to Skip to main content
15,911,785 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: * versus ** Pin
Christian Graus7-Dec-02 0:20
protectorChristian Graus7-Dec-02 0:20 
GeneralRe: * versus ** Pin
verbatin7-Dec-02 4:10
verbatin7-Dec-02 4:10 
GeneralRe: * versus ** Pin
Anonymous7-Dec-02 0:34
Anonymous7-Dec-02 0:34 
GeneralRe: * versus ** Pin
Nitron7-Dec-02 4:46
Nitron7-Dec-02 4:46 
GeneralRe: * versus ** Pin
Alvaro Mendez7-Dec-02 9:28
Alvaro Mendez7-Dec-02 9:28 
GeneralRe: * versus ** Pin
Nitron7-Dec-02 12:27
Nitron7-Dec-02 12:27 
GeneralRe: * versus ** Pin
verbatin10-Dec-02 16:13
verbatin10-Dec-02 16:13 
GeneralRe: * versus ** Pin
Nitron11-Dec-02 5:02
Nitron11-Dec-02 5:02 
wait wait wait...
first, you mis-quoted:

David Southard wrote:
int x = 5; // initializes a variable int to value
int* px = &x; // initializes a "pointer to int"


what I said was
int* px = &x; // initializes a "pointer to int" with the physical address of x.
-------   --
 |        |
 |        |- read "Address of x"
 |
 |- read "a variable 'px' of type 'pointer to int'"


This is in fact different to what you said:

David Southard wrote:
The & character dereferences a variable and that's why you see variables being passed as parameters to functions like so:

void mod(int &x, int &y)


This (int& x) is not a "pointer to int" but is in fact a "reference to int".

Consider the function:
func(CString* pszString, CString& szAnotherString)
{
  pszString->Format("A String");
  szAnotherString.Format("Some String);
}


note that the "pointer to string" (pszString) requires pointer notation for operations, however the reference to the string (szAnotherString) is just that: a "reference" to (not a copy of) the origional string.

My term "de-referencing" is not to be confused with a "reference to". That is why I am picky where and when I put the * and & modifiers on things. When I declare a pointer to a type, I always put the * modifier at the end of the type. And likewise when I declare a reference. This is different than when I de-reference a pointer or get the "address of" something else. Try this in a console app:

int main(int argc, char* argv[])
{
	int x = 5;
	printf("\nThe value x initially has the value %d", x);
	unsigned long physical_address_of_x = reinterpret_cast<unsigned long>(&x);
	int& reference_to_x = x;
	int* pointer_to_x = reinterpret_cast<int*>(physical_address_of_x);
	// change the "reference to x" and watch what happens to x.
	printf("\n\nWe are now setting reference_to_x = 12\n");
	reference_to_x = 12;
	printf("\nThe value x is located at 0x%X and now has the value %d.", physical_address_of_x, x);
	printf("\nThe reference to x is located at 0x%X and has the value %d.", &reference_to_x, reference_to_x);
	printf("\nThe pointer to x is located at 0x%X and points to location 0x%X.", &pointer_to_x, pointer_to_x);
	printf("\nThe pointer to x, when de-referenced yeilds the value %d\n\n", *pointer_to_x);

	return 0;
}


I hope that clears things up.

- Nitron


"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
GeneralRe: * versus ** Pin
Nitron11-Dec-02 5:06
Nitron11-Dec-02 5:06 
GeneralCannot download so big a Microsoft SDK, for programming GDI+ Pin
Phan Manh Dan6-Dec-02 22:09
Phan Manh Dan6-Dec-02 22:09 
GeneralRe: Cannot download so big a Microsoft SDK, for programming GDI+ Pin
Christian Graus6-Dec-02 22:39
protectorChristian Graus6-Dec-02 22:39 
GeneralRe: Cannot download so big a Microsoft SDK, for programming GDI+ Pin
Jeff Patterson7-Dec-02 11:44
Jeff Patterson7-Dec-02 11:44 
GeneralChange tooltip for close button ... Pin
Neha6-Dec-02 21:09
Neha6-Dec-02 21:09 
GeneralRe: Folder Security Pin
Mazdak7-Dec-02 7:49
Mazdak7-Dec-02 7:49 
GeneralRookie Pin
hassani6-Dec-02 19:52
hassani6-Dec-02 19:52 
GeneralRe: Rookie Pin
Michael Dunn6-Dec-02 20:22
sitebuilderMichael Dunn6-Dec-02 20:22 
GeneralRe: Rookie Pin
Christian Graus6-Dec-02 20:23
protectorChristian Graus6-Dec-02 20:23 
GeneralRe: Rookie Pin
Michael Dunn6-Dec-02 20:28
sitebuilderMichael Dunn6-Dec-02 20:28 
GeneralRe: Rookie Pin
Christian Graus6-Dec-02 20:30
protectorChristian Graus6-Dec-02 20:30 
GeneralRe: Rookie Pin
Michael Dunn6-Dec-02 20:34
sitebuilderMichael Dunn6-Dec-02 20:34 
GeneralRe: Rookie Pin
Christian Graus6-Dec-02 20:41
protectorChristian Graus6-Dec-02 20:41 
GeneralRe: Rookie Pin
KaЯl7-Dec-02 1:53
KaЯl7-Dec-02 1:53 
GeneralRe: Rookie Pin
Christian Graus6-Dec-02 20:22
protectorChristian Graus6-Dec-02 20:22 
GeneralRe: Rookie Pin
Alvaro Mendez7-Dec-02 9:26
Alvaro Mendez7-Dec-02 9:26 
GeneralRe: Rookie Pin
Christian Graus7-Dec-02 11:23
protectorChristian Graus7-Dec-02 11:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.