Pointers and Variables

I just need to clarify the variables

Does a normal variable have 2 "parts"? one part is the actual value, and the other part is the location of this value in memory

Is it correct?

So, the pointer variable is only part of the location of the normal variable, and doesn’t it matter?

+3
source share
11 answers

If you are talking about C, then pointers simply represent a different level of indirection.

a , &a ( a) - , a . a, .

p, , . - , .

, , :

int a = 7;     // set a to 7.
int *p = &a;   // set p to the address of a.

a - 0x1234 p 0x1236 (16- int/pointer). :

           +--------+
0x1236 (p) | 0x1234 |
           +--------+
0x1234 (a) | 0x0007 |
           +--------+

a , :

int b = a;

a 0x1234 b. :

int c = *p;

p 0x1236 ( 0x1234), ( '*'), a.

+7

"2 " - . - . , , 0x0004, 7 ( v).

- , . , , 0xff0c 0x0004 ( p).

C:

v 7

& v ( v) 0x0004

p - 0x0004

& p ( p) 0xff0c

* p (, p) 7

, . , , , , .

+6

, , int, . , .

, int. ( ) , . .

+1
a = 100;

a (aka & a) - , , 0x1000000, 100.

, !

+1

.
.
.

0

C, , -. . .

, , , . , .

0

int:

int x ;
x = 400 ;

x , ..

printf( "x value=%d, x memory location=%d\n", x, &x ) ;
0

, , , . , , , 0x1234. , , @ .

, , , I.e. a = 12;. a oridnary, 12. , a - @0x1234, 12 . & , , , & - C ++, address-of ( ); &a a.

: . - , I.e. a 12, ptr , , . , value-at * , , " , , ". *ptr @, ptr. , ptr = 12;, , 12 ptr, *ptr = 1;, 1 12 .

0

2 ""? - , -

: . , , ( ). , . , , , .

, - - , ?

, " ". . - . . , .

, , , , , . "".

0x16 . 0x42 , 0x16. " " . , . (, 0x20 , 0x42.

, - . "" . . , . , .

0

, . . , .

, , 32- , , 4 . , , , , 1 , , , , 4 . , 1 !.

0

. .

0

Source: https://habr.com/ru/post/1734763/


All Articles