how can i access a direct (absolute, not the offset) memory
address?

here is what i tried:
wrote a program that ask's for an address from the user,
creates a FAR pointer to that adress and shows it. then the
user can increment/decrement the value in that address by
pressing p(inc+) and m(dec-).

NOW, i compiled that program and opened it twice (in 2
different windows) and gave twice the same address to it.
now look what happen - if i change the value in
one "window" of the program, it DOES NOT change in the
other! even if they point to the same address in the memory!

here is the code snippet:
//------------------------------------------------------

#include <stdio.h> //INCLUDE EVERY KNOWN HEADER FILE
#include <conio.h> //FOR ANY CASE...
#include <iostream.h>
#include <dos.h>
#include <process.h>


main()
{
int far *ptr; //FAR POINTER!!!
long address;
char key=0; //A KEY FROM THE KEYBOARD
int temp=0;

clrscr();

cout<<"Enter Address:";
cin>>hex>>address; //GETS THE ADDRESS
clrscr();

(long)ptr=address; temp=*ptr; //PUTS THE ADDRESS IN THE PTR

cout<<"["<<hex<<(unsigned long)ptr<<"]="<<*ptr<<" = "<<
(char)(*ptr);

//SHOWS: [address]=value=ASCII symbol.


while (key!=27) //WHILE YOU DONT PRESS ESC.
{
while(!kbhit()) //WHILE KEY IS NOT PRESSED
{
if (temp!=*ptr) { temp=*ptr; clrscr(); cout<<"["<<hex<<
(unsigned long)ptr<<"]="<<*ptr<<" = "<<(char)(*ptr); };

//IF THE VALUE HAS CHANGED, CLEAR THE SCREEN AND SHOW
//AGAIN

if (key=='p') {key=0; (*ptr)++; } //INCREMENT VALUE
if (key=='m') {key=0; (*ptr)--; } //DEC. VALUE
};
key=getch(); //IF A KEY IS PRESSED, READ IT FROM THE
//KEYBOARD
};
return 0; //IF ESC WAS THE KEY, EXIT THE PROGRAM
}
//---------------------------------------------------------



how can i access a direct (absolute, not the offset) memory address? here is what i tried: wro..

Answer / Deepti Rani

Direct access to memory addresses is not recommended and can lead to unpredictable results. However, in C/C++, you can use pointers to access memory addresses. However, it is important to note that it's not possible for different processes or threads running on the same system to directly modify each other's memory.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What return value must conversion operators have in their declaration?

1 Answers  


Is c++ a software?

1 Answers  


What is constructor c++?

1 Answers  


Explain the uses oof nested class?

1 Answers  


How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?

1 Answers   Yahoo,


What is a .h file c++?

1 Answers  


Can you explain the term "resource acquisition is initialization?"

1 Answers   Amazon,


Write about the scope resolution operator?

1 Answers  


Why was c++ created?

1 Answers  


When do you call copy constructors?

1 Answers  


What is pointer to member?

1 Answers  


What is a mutex and a critical section.Whats difference between them?How do each of them work?

4 Answers   CTS,


Categories