Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What's the difference between a pointer and a reference? Please write a simple program description.
What's the difference between a pointer and a reference? Please write a simple program description.
1. In terms of memory, the system measures the memory space for the pointer, and the referenced and bound objects * * * enjoy the memory space, and the system does not allocate the content space for the referenced variables.

After the pointer is initialized, it can change the object it points to, but it must be initialized when referring to the definition. After initialization, it is not allowed to rebind the object.

3. So access the reference access object directly. Pointer access to an object is indirect access.

4。 If pa is a pointer, then *pa is a reference.

But it is very similar when used as a formal parameter, the difference is that the pointer is copied, and the reference is not copied. The process is as follows:

# include & ltstdio.h & gt

Invalid? pt(int? *? pta,int? *? ptb)

{

int? * ptc

ptc = ptapta = ptbptb = ptc

}

Invalid? ref(int? & ampra,int? & Regular budget)

{

int? RC;

rc = rara = rbrb = rc

}

Invalid? Master ()

{

int? a = 3; int? b = 4;

int? * pa = & ampa; int? * pb = & ampb;

pt(pa,Pb);

Printf ("Zhizhen:? a=%d,b=%d\n ",a,b);

ref(a,b);

Printf ("Yin Yong? a=%d,b=%d\n ",a,b);

}

The output results are as follows: