Z
Z
ZhGhost2018-03-24 21:10:41
C++ / C#
ZhGhost, 2018-03-24 21:10:41

How to understand pointer assignment in C++?

Hey! Explain why two or more are written when assigning a pointer *
. Examples:
*(DWORD**)CODE
*(DWORD*)CODE
(DWORD*)CODE
What is the difference between them? After all, according to the assignment rule, the third option is only suitable? But uses all three

Answer the question

In order to leave comments, you need to log in

3 answer(s)
1
15432, 2018-03-24
@15432

*(DWORD**)CODE = 0;- the CODE variable contains the address to a variable of the "pointer to DWORD" type. We go to this address and write NULL there
*(DWORD*)CODE = 0;- the CODE variable contains the address to the "DWORD" type variable. We go to this address and write 0 there
(DWORD*)CODE = 0;- the CODE variable contains the address to the "DWORD" type variable. We assign NULL to the CODE variable itself.

Z
ZhGhost, 2018-03-24
@ZhGhost

I'm waiting for someone "on the fingers" to explain :)

V
Vitaly Stolyarov, 2018-03-24
@Ni55aN

Let's say CODE is a pointer.

int* CODE  = new int(5);
    int b = *CODE;
    cout << b << endl ;

*CODE - take the value at the address stored in the CODE pointer
(DWORD*) - cast to DWORD type. We know that an int is stored at the pointer address, now we will work with it as with DWORD
(DWORD **) - the same thing, only the first pointer stores the address to the second pointer. The second, in turn, to the address where the value is stored, with which we will work as a DWORD

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question