Why there are no references in C language, only pointers.
This article mainly explains why there are no references in C language and there are only pointers. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn why there are no references in C language and there are only pointers.
What is a citation?
To put it bluntly, a reference is to create a new name for an existing variable, and if the program does something about the reference alias, it is actually a change to the original target.
C + + reference instance
# include # include void exchange (int & x, int & y) {int t; t = x; x = y; y = t;} int main () {int awagh b; scanf ("% d% d", & a, & b); exchange (ameme b); printf ("% d% d\ n", amaine b); getchar (); return 0;}
Program output
12 34 34 12-Process exited after 3.121 seconds with return value 0 Please press any key to continue. . .
What is the C language?
The C language is an ever-changing pointer, and when references appear in C++, it makes programming very friendly. If you look at the operation above, it looks very clear.
But we can also use pointers to do the above.
Instance code
12 34 34 12-Process exited after 3.121 seconds with return value 0 Please press any key to continue. . .
Program output
12 56 56 12-Process exited after 2.477 seconds with return value 0 Please press any key to continue. . .
Leave a topic for discussion
Discuss what the following program outputs?
# include # include void exchange (int * x, int * y) {int * t = x; * x = * y; * y = * t;} int main () {int a, b); scanf ("% d% d", & a, & b); exchange (& a, & b); printf ("% d% d\ n", aMagna b); getchar (); return 0 At this point, I believe you have a deeper understanding of why there is no reference to the C language and only pointers. You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!