What is the data type of an address and how can be manipulated directly by user? More clarification by an Ex; I have an address like 00CFFCFC and i wanna manipulate it to 00CFFCFD so what’s the data type of it and how can i make that change?
6/16/2019 12:57:06 AMMasoud HMD
6 AnswersNew Answer
for the handling in python this may be helpful: addr = '00CFFCFC' print(addr) x = 1 val1 = int(addr, 16) +1 print(hex(val1).upper()) https://code.sololearn.com/c8169L90DayF/?ref=app
The actual addresses are unsigned integers. But the data type of pointer is a pointer type, so int* c; c is of type int* double* d; d is of type double*. In it's purest form the type of pointer datatype is void* but it is restricted (can't dereference, can't do pointer arithmetic) hence you need int*, char*, float* etc . void* points to raw bytes, it is the pointer type that interprets the data properly according to base type(char, int, float etc.) A pointer to int is different from pointer to char is different from pointer to double etc. but they usually have the same size i.e sizeof(int*) == sizeof(char*) == sizeof(float*) etc. The size is platform dependent. (Note - The standard does allows to have different sizes for pointer of different datatypes) Pointer Arithmetic - means only scalar addition or subtraction to pointer values. ptr++, ptr--, ptr+=2 etc. or subtracting two pointers and storing the result in int type. int diff = ptr - ptr1; ptr = ptr - ptr1; // won't compile ptr = ptr + ptr1; // won't compile ptr = ptr * 5; // won't compile You can't add two pointers. You can't multiply or divide pointer by scalars. Be careful when manipulating pointers manually. Between 0x00CFFCFC and 0x00CFFCFD(use 0x notation for addresses, else the value will be interpreted as octal value in this case) the address has changed by 1 which indicates address is of a pointer to type char, so you should do char *ptr = (char*)0x00CFFCFC; ptr++; // ptr is now 0x00CFFCFD Subtracting two pointers gives no of elements of a type between two pointers. So say you have one int at address 0x00CFFCF0 and second at 0x00CFFCF4, then 0x00CFFCF4 - 0x00CFFCF0 will give you 1 but if you subtract as raw ints, the difference is 4.
Typically an int. Some languages such as c++ have "pointer arithmetic" meaning adding 1 to a pointer to an int will increment it by 4 bytes (the size of a 32bit int)
I doubt direct memory access is supported in Python (mentioned in Relevant Tags). In C/C++ (also mentioned in Relevant Tags) there is the pointer type, whose size depends on platform (32bit or 64bit). Pointer is a special type designed to store memory address, and through this address one can manipulate data in memory.
double d=10.0; double *dptr = &d; cout << (void*)dptr << endl; char *cptr = (char*)dptr; cout << (void*)cptr << endl; cptr++; cout << (void*)cptr << endl; dptr = (double*)(void*)cptr; cout << (void*)dptr << endl; // prints what you are looking for. if you now try to dereference the pointer, you may get segfault or garbage values.
guys 1st of all thanks for the answers but still i didn’t get the right answer, pointers are type of data that we determine what they should be and they are pointing and referring to the assigned address so as all basically know, memory allocations are automatically done for empty mem locations as per request and each time it changes to diff address and these addresses are diff at each system so i’m ganna ask the question with another Ex; suppose that we are asking for the datatype double so the memory allocation will be 8 bytes assuming the address frm 00CFFCF0 to 00CFFCF8 bites, now i wanna manipulate the address to get access to 00CFFCF1 or i intend to change the double allocation address to start frm 00CFFCF1 to 00CFFCF9 for any reason, (note that this is just an Ex for clarification purpose and here there’s no possibility to explain main goal) so now what are we do?