Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer to int. C++

Tags:

c++

pointers

int

I need to pass to function pointer to int. Now if I want to pass 5 I'm doing it like this:

int * i = NULL;
int b = 5;
i = &b;

Is there any better way to write it shorter?

I want to pass bytes that are in i int to this function:

void Write2Asm(void* pxAddress, BYTE * MyBytes,  int size)
like image 864
Hooch Avatar asked Mar 10 '11 07:03

Hooch


2 Answers

You can just pass &b to the function; no need for an intermediate pointer variable.

like image 102
Lars Noschinski Avatar answered Oct 04 '22 22:10

Lars Noschinski


Why to create a pointer variable?. Why can't you do it like this?.

int b = 5;
func(&b)
like image 40
Zimbabao Avatar answered Oct 04 '22 22:10

Zimbabao