Questions tagged [memory-address]

A number used to indicate a particular location in computer's memory. May also refer to how to access these addresses in memory.

In computing, memory address is a data concept used at various levels by software and hardware to access the computer's primary storage memory.

Memory addresses are fixed-length sequences of bits conventionally displayed and manipulated as unsigned integers. Such numerical semantic bases itself upon features of CPU (such as the instruction pointer and incremental address registers), as well upon use of the memory like an array endorsed by various programming languages.

Memory is accessed by a micro-architecture using a particular addressing mode, as defined by the software and the implementation of that micro-architecture.

Wikipedia

1569 questions
224
votes
5 answers

Correct format specifier to print pointer or address?

Which format specifier should I be using to print the address of a variable? I am confused between the below lot. %u - unsigned integer %x - hexadecimal value %p - void pointer Which would be the optimum format to print an address?
San
  • 3,413
  • 6
  • 30
  • 42
212
votes
25 answers

What exactly is a C pointer if not a memory address?

In a reputable source about C, the following information is given after discussing the & operator: ... It's a bit unfortunate that the terminology [address of] remains, because it confuses those who don't know what addresses are about, and misleads…
d0rmLife
  • 3,622
  • 6
  • 22
  • 33
186
votes
15 answers

Printing a variable memory address in swift

Is there anyway to simulate the [NSString stringWithFormat:@"%p", myVar], from Objective-C, in the new Swift language? For example: let str = "A String" println(" str value \(str) has address: ?")
apouche
  • 8,943
  • 5
  • 37
  • 45
184
votes
9 answers

Accessing Object Memory Address

When you call the object.__repr__() method in Python you get something like this back: <__main__.Test object at 0x2aba1c0cf890> Is there any way to get a hold of the memory address if you overload __repr__(), other then calling super(Class,…
thr
  • 18,022
  • 19
  • 89
  • 129
171
votes
5 answers

How can I reliably get an object's address when operator& is overloaded?

Consider the following program: struct ghost { // ghosts like to pretend that they don't exist ghost* operator&() const volatile { return 0; } }; int main() { ghost clyde; ghost* clydes_address = &clyde; // darn; that's not clyde's…
James McNellis
  • 327,682
  • 71
  • 882
  • 954
166
votes
5 answers

C++ Double Address Operator? (&&)

I'm reading STL source code and I have no idea what && address operator is supposed to do. Here is a code example from stl_vector.h: vector& operator=(vector&& __x) // <-- Note double ampersands here { // NB: DR 675. this->clear(); …
Anarki
  • 4,123
  • 4
  • 17
  • 9
150
votes
8 answers

Memory address of variables in Java

Please take a look at the picture below. When we create an object in java with the new keyword, we are getting a memory address from the OS. When we write out.println(objName) we can see a "special" string as output. My questions are: What is this…
uzay95
  • 14,378
  • 28
  • 105
  • 167
117
votes
3 answers

print memory address of Python variable

How do I print the memory address of a variable in Python 2.7? I know id() returns the 'id' of a variable or object, but this doesn't return the expected 0x3357e182 style I was expecting to see for a memory address. I want to do something like…
brno792
  • 5,369
  • 14
  • 50
  • 70
80
votes
6 answers

Print the address or pointer for value in C

I want to do something that seems fairly simple. I get results but the problem is, I have no way to know if the results are correct. I'm working in C and I have two pointers; I want to print the contents of the pointer. I don't want to dereference…
Frank V
  • 23,732
  • 32
  • 98
  • 142
68
votes
4 answers

How can I get the memory address of a JavaScript variable?

Is it possible to find the memory address of a JavaScript variable? The JavaScript code is part of (embedded into) a normal application where JavaScript is used as a front end to C++ and does not run on the browser. The JavaScript implementation…
vivekian2
  • 3,327
  • 9
  • 31
  • 41
62
votes
5 answers

Why are the memory addresses of string literals so different from others', on Linux?

I noticed that string literals have very different addresses in memory than other constants and variables (Linux OS): they have many leading zeroes (not printed). Example: const char *h = "Hi"; int i = 1; printf ("%p\n", (void *) h); printf ("%p\n",…
Noidea
  • 1,265
  • 8
  • 16
59
votes
14 answers

Is it possible to store the address of a label in a variable and use goto to jump to it?

I know everyone hates gotos. In my code, for reasons I have considered and am comfortable with, they provide an effective solution (ie I'm not looking for "don't do that" as an answer, I understand your reservations, and understand why I am using…
Joshua Cheek
  • 26,664
  • 15
  • 67
  • 81
58
votes
8 answers

Why is address of char data not displayed?

class Address { int i ; char b; string c; public: void showMap ( void ) ; }; void Address :: showMap ( void ) { cout << "address of int :" << &i << endl ; cout << "address of char :"…
user478571
52
votes
5 answers

How to print variable addresses in C?

When i run this code. #include void moo(int a, int *b); int main() { int x; int *y; x = 1; y = &x; printf("Address of x = %d, value of x = %d\n", &x, x); printf("Address of y = &d, value of y = %d, value of *y…
nambvarun
  • 1,121
  • 4
  • 12
  • 14
46
votes
5 answers

How can a non-assigned string in Python have an address in memory?

Can someone explain this to me? So I've been playing with the id() command in python and came across this: >>> id('cat') 5181152 >>> a = 'cat' >>> b = 'cat' >>> id(a) 5181152 >>> id(b) 5181152 This makes some sense to me except for one part: The…
Usagi
  • 2,678
  • 2
  • 24
  • 35
1
2 3
99 100