Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the references passed in C++?

Shulou Source: shulou.com Published: 2022-06-03 06:13:43 10月04日 Update

This article mainly explains "what are the citation transmission in C++". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Now please follow the editor's train of thought slowly and deeply. Let's study and learn what are the citation transmission in C++!

Citation delivery in C++

In C++, parameter passing includes value passing, and its usage is the same as in C language, but reference passing, as a major feature of C++, is not supported in C language.

1. Creation of reference variables: int rats;// creates reference variables rodents as aliases for rats int & rodents = rats; considerations for using reference variables:

Initialize when declared

Once associated with a variable, allegiance is only to that variable

For the first article above:

The disallowed use of int rats;// int & rodents;rodents = rats

For the second article, you can refer to the following example:

# include

< iostream >

Using namespace std;int main (void) {int rats = 10; int & rodents = rats; int bunnies = 20; cout

Tags: Parameters variables examples cases types compilers compilers results output pointers examples objects points languages errors references learning generation special events Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker MySQL Redmi Xiaomi