Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert int* to int

Tags:

Given a pointer to int, how can I obtain the actual int?

I don't know if this is possible or not, but can someone please advise me?

like image 473
paultop6 Avatar asked Apr 23 '10 14:04

paultop6


People also ask

Is int * a type?

int* means a pointer to a variable whose datatype is integer. sizeof(int*) returns the number of bytes used to store a pointer. Since the sizeof operator returns the size of the datatype or the parameter we pass to it.

How do you convert int to Java?

We can convert int to String in java using String. valueOf() and Integer. toString() methods. Alternatively, we can use String.

Can we assign int to Integer in Java?

In java one canâTMt assign a string value (containing an integer only) to an int variable directly or even by casting. In case of Integer we can assign string to an object of Integer type using the Integer(String) constructor or by even use parseInt(String) to convert a String literal to an int value.


1 Answers

Use the * on pointers to get the variable pointed (dereferencing).

int val = 42;
int* pVal = &val;

int k = *pVal; // k == 42

If your pointer points to an array, then dereferencing will give you the first element of the array.

If you want the "value" of the pointer, that is the actual memory address the pointer contains, then cast it (but it's generally not a good idea) :

int pValValue = reinterpret_cast<int>( pVal );
like image 180
Klaim Avatar answered Oct 06 '22 22:10

Klaim