Rasmus
Rasmus

Reputation: 1685

How to get a pointer's value or depointerize it

I was wondering if it's possible to make a pointer not a pointer.

The problem is I have a function that accepts a pointer for a parameter for me to easily get a value to that pointer. It's a simple int, so I was wondering if I could just get that value without needing to send around a pointer wherever I want the value to land.

I don't want the function to return the value as an int, as it's giving a value to 2 pointers!

Upvotes: 74

Views: 213672

Answers (2)

Miguel Tomás
Miguel Tomás

Reputation: 1911

To retrieve the original value from a pointer referenced to a const *void one can, for instance, code it like below:

// const* void vars[j].address;

double* tmp = (double*) vars[j].address;
double tmpv = *tmp;
Serial.println( tmpv );

Upvotes: 0

James McDonnell
James McDonnell

Reputation: 3710

To get the value of a pointer, just de-reference the pointer.

int *ptr;
int value;
*ptr = 9;

value = *ptr;

value is now 9.

I suggest you read more about pointers, this is their base functionality.

Upvotes: 114

Related Questions