There is no way in standard C++ to access arbitrary specific memory. You can create objects, and you can acquire memory for objects through std::malloc
(there's hardly ever any need to use std::malloc
though) or operator new, but you have no control over the memory address where allocations come from. Those are entirely controlled by the language implementation.
Syntactically, you may technically attempt to access arbitrary memory address simply by reinterpreting an integer value (representing some memory address). Whether one integer value represents the memory address that you expect is not guaranteed by the language and is entirely dependent on the language implementation. This is typically useful on embedded systems which don't use virtual memory.
On modern multi-tasking operating systems, such as those that you mention in the question, the memory that a process sees is not physical memory in the RAM, but virtual memory which the operating system maps onto the physical one. And attempting to access virtual memory that has not been mapped by the operating system, or has been mapped with restrictions, typically result in the operating system terminating the process in order to prevent the rogue process from corrupting data.
The operating system may provide an interface to access physical memory (or virtual memory of another process) if the accesser process has sufficient privileges. This may require special configuration of the operating system since such interfaces are typically considered a security risk.
Say I want to access the content of a memory address '4294967295d' or 'FFFF FFFFh'
When asking such question, you should first consider: Are you attempting to access the physical address, or the virtual address? Virtual address of this process or some other process? Why would this particular address contain something relevant? How do you know that? Is that knowledge reliable? Do you have permission to access that memory?
I want to know where is the x actually stored?
A variable is stored somewhere that the language implementation chose to store it. Knowing the number that represent the address is hardly ever useful.
Consider an analogy: Go to a sandy beach, lie down to the sand to see closer, and choose one grain of sand. Ask the question: What is the address of this grain of sand i.e. how many grains of sand are there to the left of this grain? There exist an answer sure... but what would you do with that knowledge? If you come to the beach the next day, the grains of sand have shifted and the address is no longer the same. Similarly, what would you do with the knowledge of knowing the numeric representation of memory address where some object is stored?
That said, it is actually possible. Simply insert the pointer into a character stream such as std::cout
, and the address will be printed in textual representation. Unless it is a pointer to character in which case it is treated differently.