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).

1184 questions
-3
votes
3 answers

In this function is defective since dereferencing null is not valid so i want to change code

long cread(long *xp) { return (xp? *xp : 0); } It is invalid since it could attempt to read from a null address So the solution suggested this code long cread_alt(long *xp){ long tem = 0; if(*xp > 0){ tem = *xp; } return tem; But I…
user10430594
-3
votes
1 answer

How is this constructor code taking pointers as arguments?

The code below has three arguments of the type double*. The code is part of an Arduino PID library and the user would typically give a reading of an analogue port or some kind of sensor as the argument for the "input" term and some fixed value or…
Ozymandias
  • 839
  • 1
  • 8
  • 13
-3
votes
1 answer

Dereferencing Pointer Array in C

I have a problem in this code segment printf("\nIn Func: %s", (*article[ctr]).artname); I use Code:Blocks and get the error "undefined reference to WinMain@16", article is a pointer array shouldn't I access it just by dereferencing it? I also tried…
Dominik
  • 25
  • 5
-3
votes
2 answers

Perl reference Dereferencing for @var1 = [($a, $b)]

I have below expression in perl @var1 = [($a, $b)] Can anyone help me to deference the value stored in var1.
Raghvendra
  • 124
  • 1
  • 10
-3
votes
1 answer

Why does pointer to array (done by &array) equal the array itself?

So I almost went all hurr durr on my classmates when they wrote that &array gives you address of the first element But turns out they are right. This sounds like inconsistency to me. We're talking about array defined like this: int numbers[] =…
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
-3
votes
2 answers

SegFault when dereferencing integer from void ptr

This is my code, Tuple.c, it produces a SegFault at the line with a comment saying so: #include #include #include void dbwait(); typedef struct STuple { int tSize; void** values; } Tuple; Tuple*…
Ashley
  • 121
  • 3
  • 14
-3
votes
4 answers

Dereferencing this pointer gives me -46, but I am not sure why

This is a program I ran: #include int main(void) { int y = 1234; char *p = &y; int *j = &y; printf("%d %d\n", *p, *j); } I am slightly confused about the output. What I'm seeing is: -46 1234 I wrote this program as an…
anon
-3
votes
2 answers

If a program contains the following code, it may crash. Why?

int *x; { int y; x = &y; } *x = 5; I think the problem is that x = &y should be changed to x = y. However, I still don't know why it would crash?
Leon Ma
  • 303
  • 4
  • 13
-3
votes
1 answer

What is the explanation for the output of the following C program?

I came across the following code on geeksquiz.com but could not understand how the expressions involving prefix, postfix and dereference operators are evaluated in C: #include #include int main(void) { int i; int *ptr =…
-3
votes
1 answer

C++ Convert number to pointer of type?

I have the following bit of code: int* anInt = new int(5); uintptr_t memAddr = (uintptr_t)&anInt; Log("memAddr is: " + std::to_string(memAddr)); int* anotherInt = (int*)&memAddr; Log("anInt is: " + std::to_string(*anInt)); Log("anotherInt is: " +…
ManIkWeet
  • 1,298
  • 1
  • 15
  • 36
-3
votes
1 answer

C++ dereferencing an instance

I'm new to C++ and I'm trying to dry up my code, for example: void gethit () { Gert.hitbox(AA.x, AA.damage); Gert.hitbox(AB.x, AB.damage); Gert.hitbox(AC.x, AC.damage); Gert.hitbox(AD.x, AD.damage); Gert.hitbox(Terbil.x,…
-3
votes
2 answers

Segmentation fault in C when trying to reference first element in char *

I have written a C function which the goal in mind to see if the chars 'b' is in the char array 'a'. I am new to pointers and learning. void contains (char const *a, char const *b) { } and am calling it as: contains("abc", "b"); From my…
asdf
  • 657
  • 1
  • 13
  • 30
-3
votes
2 answers

Int cannot be deferenced error

I am trying to take the user input from one method and use it in another. I am confused about the error because they are both of type int. public static void move() { System.out.println("What do you want to do?"); Scanner scan = new…
user2181402
  • 87
  • 2
  • 2
  • 8
-4
votes
1 answer

Perl get value of a hash in a hash

I have a Perl hash and I dont know what its content looks like. When I print out its keys and values (check attached hash loop picture) I get for values what looks like a string that contains another hash for each value (check output of hash loop…
-4
votes
3 answers

Assignment doesn't work but address of with the dereference operator does?

I've been playing around with C++ (just starting out), and I'm trying to make a program that needs a function to count the lines in C++. However, I've encountered weird behavior where normal assignment doesn't work, but assignment through address…
nshoo
  • 939
  • 8
  • 17
1 2 3
78
79