![]() |
Reference Variable is a reference to an existing variable, which is defined with the help of the & operator. In other words, reference variables are aliases of some existing variables, and then either of the two variables can be used. Updating the reference variable is same as updating the original variable. Reference variable in C++:In C++, the term “reference variable” refers to a variable that acts as an alias for another variable. Unlike pointers, which store addresses, reference variables directly refer to the variable they are bound to. Once initialized, a reference variable cannot be reseated or made to refer to another variable. Below is the implementation of Reference variable in C++:
Output name = skeeGrofskeeG referenceVar = skeeGrofskeeG Reference variable in Java:In Java, we can access an object only through reference variable. A reference variable is declared as a special data type and this data type can never be changed. Reference variables can be declared as static variables, instance variables, method parameters, or local variables. A reference variable that is declared as final cannot be reassigned as a reference to another object. In this, the data inside the object can be changed, but the reference variable cannot be changed. Below is the implementation of Reference Variable in Java:
Output Original Array: Java C++ JavaScript Modified Array: Java C++ JavaScript Reference variables are a basic concept of programming, through which a programming element is assigned a “reference” to data or memory. Learning the way these reference variables are built, used, benefits, and the techniques to make them work correctly can see developers using the variables to develop independent, strong, and superior software for use in various programming languages. |
Reffered: https://www.geeksforgeeks.org
Programming |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |