Java Programming
C Programming
C++ Programming

Explain reference variable and how it is different from pointer variable?


Top Answer
User Avatar
Wiki User
2009-09-07 22:05:41
2009-09-07 22:05:41

In JAVA, all variables are reference variables, and there are no pointer variables. Even though the platform may implement them as pointers, they are not available as such. In C, no variables are reference variables. They are a C++ enhancement. In C++ a reference variable is syntactically the same as a pointer variable, except that the use of the indirection operator (*) is implicit. You do declare reference variables slightly differently than pointer variables but, once you do so, they can be treated as non-pointer variables. Reference variables also cannot be redefined once they have been initialized to point to some object. They are const. Structurally, there is no difference between a pointer variable and a reference variable. They are both still pointers. The compiler just makes it easier to treat reference variables and non-pointer variables the same way.

User Avatar

Related Questions

Whenever memory that was in use, and was referred to by a pointer variable, is freed, and the pointer variable is not updated accordingly (setting it to NULL, for example), the pointer variable is considerred to be a dangling pointer reference.

pointer: to access data by address reference: there is no reference in C language

Pointer is a variable that stores the address of another variable. Since pointer is also akind of variable, thus pointer itself will be stored at a different memory location.

Pointer is a variable that is used to store the memory address of another variable. There are differenr types of pointers: NULL pointer THIS pointer VOID pointer NEAR pointer HUGE pointer FAR pointer WILD pointer

When a variable is passed by value, the function receives a copy of the variable. When a variable is passed by reference, the function receives a reference, or pointer, to the original data.

An alias is a reference, an alternate name for a variable or constant. You can assign the address of any variable or constant to a reference of the same type. A reference is a bit like a constant pointer to the type but, unlike a pointer, a reference has no address of its own thus you cannot store references. More importantly, references can never be NULL. They are simply an alternative name by which you can refer to an existing variable or constant. When you assign a value to an existing reference to a variable, you are assigning the value to the variable itself. When you pass a reference to a function, you are passing the address of the value being referred to, and that address is assigned to the function's reference argument and is local to the function. This is not unlike passing a pointer, but pointers may be NULL, references are guaranteed to be non-NULL (a NULL reference invalidates your program). Note that C++ references are not the same as C reference variables or constants. In C, a reference variable is simply a non-const pointer, while a reference constant is a constant pointer. Hence pointers can be dereferenced (both in C and C++). But in C++, a reference is neither a variable nor a pointer, but is constant (it always refers to the same object and cannot be reassigned once assigned).

Pointer is simply a variable that stores the memory address of another variable. Pointer to pointer means double pointer ,pointer that points to another pointer variable.

You cannot store references. A reference is nothing more than an alias, an alternate name for an existing variable or constant. References are primarily used when passing variables to functions such that the function can operate upon the variable itself -- known as passing by reference. The function refers to the variable by a different name, an alias, but it is the same variable. By contrast, when passing a variable by value the function uses a copy of that variable, assigning the variable's value to that copy. References are often confused with pointers, primarily because C uses the term to mean a pointer (hence the term, dereferencing). But in C++ a reference is a separate entity altogether. Unlike a reference, a pointer is a variable in its own right, one that can be used to store a memory address. Since a pointer has storage, you can store a pointer in a data file. However, in reality you are only storing the pointer's value -- a memory address -- not an actual pointer. Pointers and references are similar insofar as they can both refer to an object. A pointer does this by storing the memory address of the object, while a reference refers directly to the object itself. Thus if you have a pointer and a reference to the same object, the pointer's value is exactly the same as the address of the reference. Therefore the only way you can store a reference is by storing the object being referred to, not the reference itself.

pointer is the variable that holds the address of another variable

Pointer is an address (or a variable holding an address). Scale factor is something completely unrelated.

how pointers variables diffrent from ordinary variables

A pointer is a variable. Like any other variable, it consumes memory (4 bytes on a 32-bit system). So you can have as many pointers as you like, with as many levels of indirection as you like, the only limit being dictated by available memory (which can never exceed 4GB on a 32-bit system). Pointer-to-pointer variables are no different to pointer variables (and therefore have the same limitation as pointer variables), except that a pointer variable points to a non-pointer variable (such as int) whereas a pointer-to-pointer variable points to a pointer variable of the same type (which, in turn, points to a non-pointer variable of the same type). In other words, pointer-to-pointer variables add an extra level of indirection. You can also indirect pointer-to-pointer variables via pointer-to-pointer-to-pointer variables, and so on. Pointer indirection is useful because, without them, pointers would always be passed to functions by value (never by reference). Passing by value copies the pointer variable, which means you can mutate the memory it points to, but you cannot change where it points (because that would only affect the copy, not the original pointer that was passed). To pass a pointer by reference you must pass the pointer indirectly, via a pointer-to-pointer, which is itself passed by value. This allows the function to mutate the pointer variable (changing where it points), as well mutating the memory it points to. Indirect pointers are also useful when allocating dynamic multi-dimensional arrays because each additional dimension requires an additional level of indirection.

Well, the pointer is a type of variables that stores an address in the Memory.the reference is the address itself of a variable.

Pointer is a variable, A variable that stores the address of another variable. Size of a pointer is 2 bytes.

As the name suggests Pointer is used to point towards something ,here in this case it points to another variable and stored at a memory location. Pointer is a variable that stores address of another variable. Different Types of pointers are: 1)Dangling Pointers 2)NULL Pointers 3)This Pointer 4)Generic Pointer 5)Near Pointer 6)Far Pointer

Reference VariableIt does not have separate memory other than variableIt is just an alias created to existing variableIt is not present C languagePointer VariableIt has separate memory other than variableIt actually stores address of the variableIt is present in C as well as C++.

Pointer is a variable that stores the address of another variable . So pointer basically stores the address of another variable and size of pointer can be evaluated by using sizeof operator.

A Pointer is a Variable that holds a memory address, usually the location of another variable in memory. A pointer to pointer is known as double pointer.

A pointer is a variable which is used to store address of a variable. They are used to point to another *p; // creates a pointer of integer typeint num; // an integer variablep=# //pointer variable p is assigned with address of num

a pointer is a variable .it specify the address of the particular variable ,the & symbol is to specify the address of the variable.

A pointer is a variable that stores a memory address. If the address is non-null (non-zero) that address can be dereferenced to access the value stored at that address. Pointers are necessary when referring to objects allocated on the heap because objects on the heap have no name, they can only be accessed via their memory address (their actual identity). Resource handles and smart pointer objects allow access to heap-based objects in languages that have no concept of a "raw" pointer. Pointers are also useful in that the same variable can be used to refer to different objects simply by changing the address stored in the pointer. This makes it possible to pass by reference in languages that only support pass by value semantics. Pointers are copied, but the since the value of a pointer is an address, it is the same as passing the address, by reference.

with the help of pointers we able to store the memory location of any variable. In c the pointer variable is use to store the memory location of any variable. The pointer variable is define as a simple variable but in pointer variable use a special "*" character at the left most side of name of pointer variable. If any variable name have * it means it is a pointer variable it hold the memory location of variable.

It is meaningless because a reference is not a variable of any kind. A reference is simply an alias for an already existing object and, once assigned, cannot be reassigned to another object. Although a reference is not variable, the object it refers to can be. Note that a reference is not the same as a pointer, although they share some similar properties. A pointer is a variable that stores the address of an object and allows the object to be accessed through indirection (dereferencing). However, pointers can be reassigned and may be NULL while references cannot. References are easier to work with, but pointers are more flexible.

Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;

normal variable contains the value of variable ( or float) whereas pointer variable contains the address of another variable

Copyright ยฉ 2020 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.