geekcode geekcode -4 years ago 42
C Question

How to localize address of the beginning of the memory area? [C lang]

I learned C language and I have some questions.

If the best way to find address of the beginning of a memory area is to use pointers?

For example in a few steps

1) I have variable int a = 1;

2) I declare pointer to variable a: int *pointer_a;

3) I assign variable a to pointer: pointer_a = a;

4) Now, I want to print address in memory area:
printf("Adress variable a= %p", &pointer_a);

Am I doing it right?

Answer Source

pointer_a should hold memory address of variable a, that's what pointers do. as far as pointers are concern & is the address of operator.

pointer_a = &a;

and then you can. printf("Address variable a = %p", &pointer_a);

you can still directly printf("Address variable a = %p", &a);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download