Click here to Skip to main content
15,908,909 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Different Between the operator '*' and '&' Pin
«_Superman_»5-Mar-09 17:42
professional«_Superman_»5-Mar-09 17:42 
AnswerRe: Different Between the operator '*' and '&' [modified] Pin
PIEBALDconsult5-Mar-09 3:47
mvePIEBALDconsult5-Mar-09 3:47 
GeneralRe: Different Between the operator '*' and '&' Pin
Cedric Moonen5-Mar-09 3:50
Cedric Moonen5-Mar-09 3:50 
GeneralRe: Different Between the operator '*' and '&' Pin
PIEBALDconsult5-Mar-09 3:55
mvePIEBALDconsult5-Mar-09 3:55 
GeneralRe: Different Between the operator '*' and '&' Pin
bulg5-Mar-09 7:02
bulg5-Mar-09 7:02 
GeneralRe: Different Between the operator '*' and '&' Pin
PIEBALDconsult5-Mar-09 10:38
mvePIEBALDconsult5-Mar-09 10:38 
AnswerRe: Different Between the operator '*' and '&' Pin
jeansea5-Mar-09 4:14
jeansea5-Mar-09 4:14 
AnswerRe: Different Between the operator '*' and '&' Pin
ky_rerun5-Mar-09 4:39
ky_rerun5-Mar-09 4:39 
in a declaration ie int *X means a a pointer to x named *;

You cannot define a reference with initializing it

so
int &X //doesn't work however
---
int Y;
int &x = Y; does


Y and X now refer to the same place in memory changing the value of one will change the value of the other. When you use a & in a function prototype we are saying I want my parameter to access memory at the location of the variable the caller specified; When you declare a pointer in the prototype you are going to explicitly pass in a pointer that pointer can however be reassigned but once reassinged the caller will no longer be able to read changes to what was passed in

I wrote a little example.
<br />
 // CppTest.cpp : Defines the entry point for the console application.<br />
//<br />
<br />
#include "stdafx.h"<br />
<br />
<br />
void NoSideEffect(int *T)<br />
{<br />
	<br />
	int G = 5;<br />
	T = &G;<br />
<br />
<br />
}<br />
<br />
void SideEffect(int &T)<br />
{<br />
	int G = 5;<br />
	T = G;<br />
}<br />
<br />
void PointerSideEffect(int *T)<br />
{<br />
	int G = 10;<br />
	*T = G;<br />
}<br />
<br />
<br />
<br />
int _tmain(int argc, _TCHAR* argv[])<br />
{<br />
	char buffer[2];<br />
	int X = 2;<br />
	NoSideEffect(&X);<br />
	printf("X is Now %d \n",X);<br />
	SideEffect(X);<br />
	printf("X is Now %d \n",X);<br />
	PointerSideEffect(&X);<br />
	printf("X is Now %d \n",X);<br />
	gets(buffer);<br />
}<br />
<br />



this will print out


X is Now 2
X is Now 5
X is Now 10



a programmer traped in a thugs body

GeneralRe: Different Between the operator '*' and '&' Pin
jeansea5-Mar-09 5:19
jeansea5-Mar-09 5:19 
GeneralRe: Different Between the operator '*' and '&' Pin
ky_rerun5-Mar-09 5:56
ky_rerun5-Mar-09 5:56 
AnswerRe: Different Between the operator '*' and '&' Pin
Maximilien5-Mar-09 4:42
Maximilien5-Mar-09 4:42 
GeneralRe: Different Between the operator '*' and '&' Pin
PIEBALDconsult5-Mar-09 10:38
mvePIEBALDconsult5-Mar-09 10:38 
GeneralRe: Different Between the operator '*' and '&' Pin
«_Superman_»5-Mar-09 17:34
professional«_Superman_»5-Mar-09 17:34 
QuestionCan anybody let me know how to handle the move event in SDI Pin
ashokbngr5-Mar-09 3:24
ashokbngr5-Mar-09 3:24 
AnswerRe: Can anybody let me know how to handle the move event in SDI Pin
Code-o-mat5-Mar-09 4:02
Code-o-mat5-Mar-09 4:02 
QuestionUnable to control mouse events Pin
AprNgp5-Mar-09 0:23
AprNgp5-Mar-09 0:23 
AnswerRe: Unable to control mouse events Pin
Akt_4_U5-Mar-09 0:29
Akt_4_U5-Mar-09 0:29 
GeneralRe: Unable to control mouse events Pin
AprNgp5-Mar-09 0:32
AprNgp5-Mar-09 0:32 
GeneralRe: Unable to control mouse events Pin
«_Superman_»5-Mar-09 0:42
professional«_Superman_»5-Mar-09 0:42 
GeneralRe: Unable to control mouse events Pin
AprNgp5-Mar-09 0:49
AprNgp5-Mar-09 0:49 
GeneralRe: Unable to control mouse events Pin
«_Superman_»5-Mar-09 0:57
professional«_Superman_»5-Mar-09 0:57 
GeneralRe: Unable to control mouse events Pin
Akt_4_U5-Mar-09 0:47
Akt_4_U5-Mar-09 0:47 
QuestionAssertion in atlsimpstr Pin
Davitor4-Mar-09 23:47
Davitor4-Mar-09 23:47 
AnswerRe: Assertion in atlsimpstr Pin
Hamid_RT4-Mar-09 23:59
Hamid_RT4-Mar-09 23:59 
AnswerRe: Assertion in atlsimpstr Pin
Cedric Moonen5-Mar-09 0:06
Cedric Moonen5-Mar-09 0:06 

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.