473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

read memory address

Is it possible to read a memory address with C++;

For example, If I run this code first:

*************
#include <iostream>
using namespace std;
void main()
{
int *zz = new int;
*zz = 79;
cout << zz << endl;
}
*************

And suppose the output will be 00322E70 .

Now, can I write a new program in C++, and Access the memory address
00322E70 and check what is in there?

So I am thinking of something Like the following code, though the following
DOES NOT WORK:

*************
#include <iostream>
using namespace std;
void main()
{
int *zz;
zz = 00322E70;
cout << *zz << endl;
}
*************
Jul 23 '05 #1
4 13695
Someonekicked wrote:
Is it possible to read a memory address with C++;
Not portably, but yes.
For example, If I run this code first:

*************
#include <iostream>
using namespace std;
void main()
int main()
{
int *zz = new int;
*zz = 79;
cout << zz << endl;
}
*************

And suppose the output will be 00322E70 .

Now, can I write a new program in C++, and Access the memory address
00322E70 and check what is in there?
It's in the "virtual memory space" of your program. What physical area
it corresponds to in your platform is beyond the scope of the language and
has to be asked about in a newsgroup for your platform.
So I am thinking of something Like the following code, though the following
DOES NOT WORK:

*************
#include <iostream>
using namespace std;
void main()
int main()
{
int *zz;
zz = 00322E70;
You need to (a) form the literal correctly by prefixing it with '0x' and
(b) use reinterpret_cast<int*>:

zz = reinterpret_cast<int*>(0x00322E70);

However, if that address does not really represent an 'int', using the
pointer resulting from such conversion has undefined behaviour. So, C++
imposes no requirements on that program to do anything in particular.
cout << *zz << endl;
}
*************


V
Jul 23 '05 #2
Someonekicked wrote:
For example, If I run this code first:

*************
#include <iostream>
using namespace std;
void main()
Use Google on this newsgroup for "void main", and for "using namespace std".

From whom are you learning these things?
{
int *zz = new int;
*zz = 79;
cout << zz << endl;
}
*************

And suppose the output will be 00322E70 .

Now, can I write a new program in C++, and Access the memory address
00322E70 and check what is in there?


Google for "virtual memory". Each time you run a program, a modern OS will
construct virtual memory for the program, using a secret hardware table of
offsets to real memory. Each time you run the memory could be different.

And all of this is platform specific: The C++ itself won't define the result
of pointing to a memory address that does not contain a well-formed C++
object.

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #3
ben
you can use reinterpret_cast to achieve it but i am looking forward to some
memory violation crashes :)

ben
Jul 23 '05 #4
thx for your reply
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:Cw****************@newsread1.mlpsca01.us.to.v erio.net...
Someonekicked wrote:
Is it possible to read a memory address with C++;


Not portably, but yes.
For example, If I run this code first:

*************
#include <iostream>
using namespace std;
void main()


int main()
{
int *zz = new int;
*zz = 79;
cout << zz << endl;
}
*************

And suppose the output will be 00322E70 .

Now, can I write a new program in C++, and Access the memory address
00322E70 and check what is in there?


It's in the "virtual memory space" of your program. What physical area
it corresponds to in your platform is beyond the scope of the language and
has to be asked about in a newsgroup for your platform.
So I am thinking of something Like the following code, though the
following DOES NOT WORK:

*************
#include <iostream>
using namespace std;
void main()


int main()
{
int *zz;
zz = 00322E70;


You need to (a) form the literal correctly by prefixing it with '0x' and
(b) use reinterpret_cast<int*>:

zz = reinterpret_cast<int*>(0x00322E70);

However, if that address does not really represent an 'int', using the
pointer resulting from such conversion has undefined behaviour. So, C++
imposes no requirements on that program to do anything in particular.
cout << *zz << endl;
}
*************


V

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Sebastian Krause | last post by:
Hello, I tried to read in some large ascii files (200MB-2GB) in Python using scipy.io.read_array, but it did not work as I expected. The whole idea was to find a fast Python routine to read in...
0
by: munif | last post by:
i wnat write a C++ program that would read from a CD and display information about files and folders in the given CD In simple words you would be performing a simple (ls -l) or (DIR /S) on the...
2
by: hvaisane | last post by:
Valgrind says ==11604== Invalid read of size 4 ==11604== at 0x8048ABB: main (foo.cc:36) ==11604== Address 0x1B92415C is 4 bytes inside a block of size 8 free'd ==11604== at 0x1B90514F:...
19
by: Holger Hasselbach | last post by:
- The value of the object allocated by the malloc function is used (7.20.3.3). - The value of any bytes in a new object allocated by the realloc function beyond the size of the old object are used...
19
by: Mark Richards | last post by:
I've been programming for many years, but have only recently taken a deep "C" dive (bad pun, i know) and need a lot of explanation from an expert. My questions center around those mysterious...
5
by: Pete | last post by:
I having a problem reading all characters from a file. What I'm trying to do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want to && with a mask 0xFF000000 then >> right...
22
by: Brad | last post by:
Hi, Am trying to read one byte at location 0xFFF0 000E in an embedded system. I cast a pointer to int, then try to stuff the above address in, then reference whats at the location? wont...
7
by: alexandre_irrthum | last post by:
Hi there, I am trying to use pyserial to read data from a temperature logger device (T-logger). T-logger is based on the DS1615 temperature recorder chip (Dallas Semiconductor). According to the...
28
by: tlpell | last post by:
Hey, read some tips/pointers on PHP.net but can't seem to solve this problem. I have a php page that reads the contents of a file and then displays the last XX lines of the file. Problem is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.