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

1793 questions
260
votes
6 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,933
  • 7
  • 34
  • 43
239
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
  • 9,703
  • 6
  • 40
  • 45
224
votes
6 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,983
  • 4
  • 19
  • 9
223
votes
24 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
  • 4,112
  • 7
  • 24
  • 33
222
votes
12 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
  • 19,160
  • 23
  • 93
  • 130
173
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
  • 348,265
  • 75
  • 913
  • 977
169
votes
9 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
  • 16,052
  • 31
  • 116
  • 182
156
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
  • 6,479
  • 17
  • 54
  • 71
84
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,795
  • 9
  • 35
  • 41
82
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
  • 25,141
  • 34
  • 106
  • 144
74
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
  • 30,436
  • 16
  • 74
  • 83
69
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
67
votes
2 answers

How to printf a memory address in C

My code is: #include #include void main() { char string[10]; int A = -73; unsigned int B = 31337; strcpy(string, "sample"); // printing with different formats printf("[A] Dec: %d, Hex: %x,…
varlotbarnacle
  • 821
  • 1
  • 6
  • 7
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,405
  • 11
  • 17
57
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,201
  • 4
  • 13
  • 14
1
2 3
99 100