Questions tagged [dereference]

Anything related to pointer dereference, i.e. the process of determining the object which the pointer is referring to. Languages having pointer variables usually have a special operator to perform dereferencing of pointers (e.g. in C and C++, if `p` is a valid pointer, `*p` is the object pointed to by `p`).

Anything related to pointer dereference, i.e. the process of determining the object which the pointer is referring to. Languages having pointer variables usually have a special operator to perform dereferencing of pointers (e.g. in C and C++, if p is a valid pointer, *p is the object pointed to by p).

1032 questions
588
votes
6 answers

What does "dereferencing" a pointer mean?

Please include an example with the explanation.
asir
  • 11,193
  • 8
  • 22
  • 18
289
votes
3 answers

Why does the arrow (->) operator in C exist?

The dot (.) operator is used to access a member of a struct, while the arrow operator (->) in C is used to access a member of a struct which is referenced by the pointer in question. The pointer itself does not have any members which could be…
Askaga
  • 5,379
  • 4
  • 20
  • 45
69
votes
2 answers

org.hibernate.QueryException: illegal attempt to dereference collection

I am trying following hql query to execute SELECT count(*) FROM BillDetails as bd WHERE bd.billProductSet.product.id = 1002 AND bd.client.id = 1 But it is showing org.hibernate.QueryException: illegal attempt to dereference…
xrcwrn
  • 4,867
  • 17
  • 58
  • 117
69
votes
2 answers

Dereference vector pointer to access element

If i have in C++ a pointer to a vector: vector* vecPtr; And i'd like to access an element of the vector, then i can do this by dereferncing the vector: int a = (*vecPtr)[i]; but will this dereferencing actually create a copy of my vector on…
Mat
  • 9,423
  • 10
  • 40
  • 48
68
votes
7 answers

dereferencing pointer to incomplete type

I've seen a lot of questions on this but I'm going to ask the question differently without specific code. Is there a way of EASILY determining what is causing the type to be incomplete? In my case I'm using someone elses code and I'm completely…
nick
  • 1,025
  • 1
  • 10
  • 16
68
votes
11 answers

Checking if an iterator is valid

Is there any way to check if an iterator (whether it is from a vector, a list, a deque...) is (still) dereferenceable, i.e. has not been invalidated? I have been using try-catch, but is there a more direct way to do this? Example: (which doesn't…
huff
  • 1,855
  • 2
  • 27
  • 49
68
votes
7 answers

Meaning of "referencing" and "dereferencing" in C

I read different things on the Internet and got confused, because every website says different things. I read about * referencing operator and & dereferencing operator; or that referencing means making a pointer point to a variable and dereferencing…
Milkncookiez
  • 4,997
  • 10
  • 46
  • 76
57
votes
6 answers

Why is the dereference operator (*) also used to declare a pointer?

I'm not sure if this is a proper programming question, but it's something that has always bothered me, and I wonder if I'm the only one. When initially learning C++, I understood the concept of references, but pointers had me confused. Why, you ask?…
diggingforfire
  • 3,205
  • 1
  • 21
  • 33
57
votes
1 answer

Why would code explicitly call a static method via a null pointer?

I've seen code like this in a couple of old projects: class Class { static void Method() {} }; ((Class*)0)->Method(); This code contains undefined behavior because it includes dereferencing a null pointer (no matter what happens afterwards).…
sharptooth
  • 159,303
  • 82
  • 478
  • 911
55
votes
3 answers

Meaning of the ampersand '&' and star '*' symbols in Rust

Despite thoroughly reading the documentation, I'm rather confused about the meaning of the & and * symbol in Rust, and more generally about what is a Rust reference exactly. In this example, it seems to be similar to a C++ reference (that is, an…
John Smith Optional
  • 15,639
  • 10
  • 36
  • 54
55
votes
5 answers

Dereferencing a pointer to 0 in C

Sometimes data at memory address 0x0 is quite valuable -- take x86 real mode IVT as a more known example: it starts at 0x0 and contains pointers to interrupt handlers: a dword at 0x00 is a pointer to division by zero error handler. However, C11…
gfv
  • 774
  • 6
  • 12
45
votes
4 answers

Does dereferencing a pointer make a copy of it?

Does dereferencing a pointer and passing that to a function which takes its argument by reference create a copy of the object?
wrongusername
  • 16,698
  • 33
  • 118
  • 201
43
votes
5 answers

C programming: Dereferencing pointer to incomplete type error

I have a struct defined as: struct { char name[32]; int size; int start; int popularity; } stasher_file; and an array of pointers to those structs: struct stasher_file *files[TOTAL_STORAGE_SIZE]; In my code, I'm making a pointer to the…
confusedKid
  • 3,221
  • 5
  • 28
  • 47
40
votes
2 answers

Why does printing a pointer print the same thing as printing the dereferenced pointer?

From the Rust guide: To dereference (get the value being referred to rather than the reference itself) y, we use the asterisk (*) So I did it: fn main() { let x = 1; let ptr_y = &x; println!("x: {}, ptr_y: {}", x, *ptr_y); } This…
Vega
  • 1,830
  • 4
  • 17
  • 29
39
votes
10 answers

How to understand the pointer star * in C?

I'm struggling with the pointer sign *, I find it very confusing in how it's used in both declarations and expressions. For example: int *i; // i is a pointer to an int But what is the logic behind the syntax? What does the * just before the i…
Jeffrey
  • 393
  • 1
  • 4
  • 4
1
2 3
68 69