cpp / c++ get pointer value or depointerize pointer

C++Pointers

C++ Problem Overview


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 an paramater 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!

C++ Solutions


Solution 1 - C++

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRasmusView Question on Stackoverflow
Solution 1 - C++James McDonnellView Answer on Stackoverflow