answersLogoWhite

0

What is dereferencing pointer?

Updated: 8/11/2023
User Avatar

Savithateamo

Lvl 1
9y ago

Best Answer

They're related but not totally comparable.

A pointer is an address in memory where a variable is located.

An array is a conceptual data representation consisting of a list of more than one item of a particular scalar type (int, float, char, structure, etc.) where each element is accessed by its index. The index can be thought of as a counter or enumerator telling you how many elements you have to skip over to get to the one you're interested in. Here's where addresses come in ... the location of a particular element in memory is offset from the so-called base address (i.e. the address of the starting element) by the value

(sizeof(one element) * index #)

The C compiler is smart enough to take the sizeof() into account when you do pointer arithmetic, so you can find the address of the i-th element as (address of base) + i, rather than having to do the multiplication explicitly.

The idea of element address as offset also accounts for C's use of zero-relative array definitions. Since the first element is offset by 0 positions from the first element its index in C is 0, not 1. The second (ordinal) element is offset from the first by 1 position so its index is 1, and so on.

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

16y ago

The difference that i learnt very recently and the one i remember :-)

Reference cannot be changed whereas pointer value can be changed.

Actually, const pointer = reference.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

There is a difference: a pointer is a number that literally points to a place in memory. Arrays are groupings of a type. There is a close relationship between pointers and arrays, however: every expression with arrays (example: array[i]) can be expressed with pointers (example: *(array + i)), because for the computer, an array is just a list of pointers to the type of the array.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

1. A pointer when declared uses additional memory. e.g.

int a=10;

int *ptr=&a;

Here, to store the address of 'a', ptr needs an additional memory.

On the contrary, a reference variable can be assumed to be just another name

given to an existing variable. Hence, it requires no additional memory as it isn't

storing any address.

2. A reference variable needs to be initialized when declared. No such case with pointers. e.g.

int a=10,*ptr; // Works fine

int &b; // Error.

3. A pointer after initialization can be re-initialized, whereas a reference variable cannot. e.g.

int a=10, b=20, *p;

int &c=a;

p=&a; // Fine.

p=&b; // Fine.

&c=b; // Error.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

A pointer is an object that contains the address of another object.

A deference'ed pointer is an object. It was a pointer, but its address was used to locate and use that other object as if it was the original target of the instruction.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

A pointer is a variable that stores a memory address. We say the variable "points-to" that memory address. A memory address is also known as a reference. Dereferencing a memory address returns the value stored at that address.

Consider the following:

int i = 42;

When we use i we are referencing the memory where the value 42 is stored. To obtain the actual memory address itself we use the address-of operator (&) which allows us to store that memory address in a pointer variable:

int* p = &i;

Since p is a variable it has an address of its own, &p. The value of p is the address of i. In order to access the value of i through p, we must dereference p with the dereference operator, *p. Thus &i returns the address of i while i itself returns the value of i, 42. &p returns the address of p, p returns the value of p, which is the address of i and *p returns the dereferenced value of p, which is 42, the value stored at address &i.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

--> Array is a collection of same kind of data.

--> Pointer is a memory location where the data stored in the memory

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

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

the reference is the address itself of a variable.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

arrays are the reserved sets of variables, which are supposed to store the similar data.

pointers are the special variables which store the address of other variables.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is dereferencing pointer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is a use of dereferencing operator?

A pointer variable contains the address to some memory location. "Dereferencing" the pointer means getting the value stored at that memory location.


What dire consequences could result from dereferencing a dangling pointer?

This could lead to a memory leak


What is the effect of dereferencing a null pointer variable?

You'd get a memory access violation. Nothing serious besides the fact that your program crashes (which is a good thing).


What is a segmentation fault?

An error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.


What is a segment fault?

An error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers in the source code, dereferencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.


What is dangling pointer reference?

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.


What is the purpose of the operator '' when used with a pointer variable?

When a pointer variable stores a non-zero memory address, we can use the dereference operator to access the value stored at that address. This is what we mean by dereferencing and is also known as indirection because we can access a value indirectly through a pointer variable. Note that if the stored address is zero, we must not dereference the pointer as the zero address indicates that the pointer is not currently pointing at any object in particular. The zero address is a reserved address so no object can ever be allocated to it.


How can an individual structure member be accessed in terms of its corresponding pointer variable?

By dereferencing the pointer variable. This can be achieved in two ways: typedef struct s { int i; float f; }; void f (struct s* p) { int x = p->i; /* using pointer to member operator */ float y = (*p).f; /* using dereference operator */ } The two methods are functionally equivalent.


Dereferencing operator in c?

When we are talking about dereferencing in C we are talking about the pointers and how to get value from them, not address.Dereferencing operator notation is "*".Here is a simple example of dereferencing:int num;int pNum*;pNum = # /* make pNum pointer point to numlocation in memory/stack */*pNum = 7; /* setting pNum value to 7. Note! numvalue becomes 7 too, because pNum points to the same memory location as num */


How many bytes are read in pointers by pointers dereferencing?

When you dereference a pointer you "read" the number of bytes determined by the pointer's type. That is, a char pointer dereferences a single byte while an int pointer dereferences 4 bytes (assuming a 32-bit int) -- regardless of the type actually stored at that address. However, note that a pointer can only actually point at a single byte since it only has storage for a single memory address. How many additional bytes are dereferenced is entirely dependant on the type of the pointer. To determine how many bytes are actually allocated to an address, use the sizeof operator, passing a dereferenced pointer (the pointer must point at the start of the allocation). If the pointer points at several elements of the same type (an array), then divide the total bytes by the size of the pointer's type to determine the number of elements in the array.


What is difference between direct addressing and indirect addressing in c plus plus?

Indirect addressing uses a pointer. Indirectly accessing the memory being pointed at is known as dereferencing. Direct addressing uses a variable's name or a reference to obtain the value.


What is the five steps how application programs transfer in and out of RAM?

Well, that depends on what you mean by that. If you are writing a program, that may be accomplished by referencing a variable name, or dereferencing a pointer. However, if you mean machine language, it will be dependent on the type of processor in use, and what system it's running on. Most cpus have the ability to fetch a memory address from a pointer in a register into another register, but the actual process will be platform dependent.