There is probably a very simple answer to this question, but I just do not see it.
#include <stdio.h> int main(void) { int x = 0; printf("\n%d\n%d\n",x,&x); }
Ok, so printf gives 0 (x) and 2293752 (& x). I'm trying to find a way to look at any address (&) and see what is already stored there. It is just for experimentation. Any help?
void* memAddr = (void*)0xAABBCCDD; //put your memory address here printf("int value at memory address %p is %i", memAddr, *((int*)memAddr));
You will probably find that looking at arbitrary memory addresses will crash.
This will dereference the pointer, which is the * operator. However, you cannot tell what type of data is stored for a random address.
#include <stdio.h> int main(void) { int x = 0; printf("\n%d\n%d\n%d\n",x,&x,*(&x)); } /* resulting output will be 0, some memory address, and 0 again */
, , , , , .
, , char int, int 4 , , char.
, 8- ASCII- - , , , - , base2, base8 base16.
- , - , , ASCII.
, , . , C , . , .
, , , . , , . , , .
, , , . UNIX . , , . - .
!
If you want to learn about memory, I would recommend using a low-level debugger like OllyDbg .
Assuming that you want to look at the "raw" data and know the address inside the address space of your process, you should do the following:
long x=<address> printf("%x", *(int *)x);
to see the address you can use% p
printf("%p",&x);
I recommend you start reading about pointers, a pointer is a variable that stores a memory address
int x=10; int *p; //this is a pointer to int p=&x; //now p has the memory location of x printf("%d\n",*p); //this will print 10
Source: https://habr.com/ru/post/1714178/More articles:What should I know about development for 64-bit applications? - c #Build Managment: проект Eclipse и проект Eclipse Managed Make - c++UIButton and setImage: do not work in sequence - inconsistent - iphoneThe difference between abstract and general code - javaHow to optimize this slow (very slow) MySQL query? - optimizationDoes source incompatibility always mean binary incompatibility? - c ++PHP Chat Bot: Google Talk - phpSQL: SELECT IN is faster and better? - sqlC # .NET runtime object type - reflectionInitializing a std :: string from a character - c ++All Articles