answersLogoWhite

0


Best Answer

In order to read a memory address you must hold a reference to that address. If the object at that address is a named object, then the object's name is a reference, thus we can simply take its address using the address-of operator (unary &):

int i = 42;

printf ("Variable i resides at memory address 0x%x\n", &i);

If we wish to store the address we must use a pointer variable of the appropriate type:

int* p = %i;

Like any other variable, a pointer variable has an address of its own, thus we can read its address:

printf ("Variable p resides at memory address 0x%x\n", &p);

To read the address being pointed at we simply examine the pointer's value:

printf ("Variable p refers to memory address 0x%x\n", p);

Note this address is the same as the address of i, the object being referred to (pointed at).

To read the value stored at the address being pointed at we must dereference the pointer (unary *). Dereferencing is also known as indirection because we are indirectly accessing the object's value:

printf ("Variable p refers to the value %d\n", *p); // e.g., 42

Pointers can refer to both named and anonymous objects. Anonymous objects are simply objects allocated on the heap at runtime. Since they don't exist at compile time we cannot name them:

int* anon = malloc (sizeof (int)); // allocate memory

Note that anon is the name of the pointer, not the object being pointed at.

printf ("The anonymous variable resides at memory address 0x%x\n", anon);

free (anon); // always release heap allocations as soon as we are finished with them!

Pointers also make it possible to pass memory addresses to and from functions (also known as pass by reference):

void f (int* p) {

}

int a = 42;

f (&a); // pass the address of a to the f() function

Note that all variables in C are passed by value, but when we pass a pointer by value we are passing an address and an address is a reference. Passing references is useful when the object being referred to cannot be efficiently passed by value. Typically this means any value that is larger than the word value of the underlying architecture (e.g., 4 bytes on a 32-bit system). Arrays in particular are never passed by value, hence an array implicitly converts to a pointer.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do I read a memory address with borland c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is difference between Turbo and Borland C?

turbo is word to do the programming language in c & c++ and i do no about borland


How do i convert a Microsoft vc project into Borland c project?

Suggest you peruse the Borland newsgroups, there are some very experienced people there who could answer you. I don't use Borland C, but Borland C++ Builder, and they have a Wizard that can build a project from VC projects included. Good luck, M


What is an address in C plus plus programming?

An address in C or C++ is the location in memory of an object or function. An address is the contents of a pointer, as opposed to the contents of the memory location pointed to by the pointer.


Who is the developer of Turbo C?

Borland.


Where can 'Borland C Book' be read in e-book form?

Wherever you want to. Provided you have an e-book reader, and you have got the book on it.


What has the author Edmund W Faison written?

Edmund W. Faison has written: 'Borland C [plus plus] 4 object-oriented programming' 'Borland C++ 3 object-oriented programming' -- subject(s): Borland C++, C++ (Computer program language), Object-oriented programming (Computer science) 'BorlandC[plus plus] 4.5 object-oriented programming' -- subject(s): Borland C., C., Object-oriented programming (Computer science) 'Borland C++ 3.1 object-oriented programming' -- subject(s): Borland C++, C++ (Computer program language), Object-oriented programming (Computer science)


Who is the author of Borland Turbo C?

A company called Borland. (Actually it was based on the former product Wizard C of Bob Jervis.)


What has the author Jason Vokes written?

Jason Vokes has written: 'Borland C++Builder 3 for dummies' -- subject(s): Borland C++Builder, C++ (Computer program language)


What is the use of header file graphics in c plus plus programming?

It has no use in C++ itself, it is only useful in Borland Turbo C++. It provides generic graphics support for Borland Turbo C++ applications.


Can borland compiler perform the graphics in c?

No. But programs compiled with Borland compilers might be able, platform-dependent.


Who develop the turbo c plus plus?

The company Borland developed Turbo C++.


How do you read input of a programme from a text file using borland c compiler from command prompt?

Use functions like fopen, fclose, fgets, sscanf, strtok