Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign pointer address manually in C programming language?

Tags:

c

pointers

memory

How do you assign a pointer address manually (e.g. to memory address 0x28ff44) in the C programming language?

like image 411
Irakli Avatar asked Dec 25 '10 22:12

Irakli


People also ask

How do you manually assign a pointer to an address?

To access address of a variable to a pointer, we use the unary operator & (ampersand) that returns the address of that variable. For example &x gives us address of variable x.

How do you store the address of a pointer in C?

A pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the address of another variable. Declaring a pointer is the same as declaring a normal variable except you stick an asterisk '*' in front of the variables identifier.

How do you set a pointer?

The syntax of declaring a pointer is to place a * in front of the name. A pointer is associated with a type (such as int and double) too. Naming Convention of Pointers: Include a "p" or "ptr" as prefix or suffix, e.g., iPtr, numberPtr, pNumber, pStudent.


1 Answers

Like this:

void * p = (void *)0x28ff44; 

Or if you want it as a char *:

char * p = (char *)0x28ff44; 

...etc.

If you're pointing to something you really, really aren't meant to change, add a const:

const void * p = (const void *)0x28ff44; const char * p = (const char *)0x28ff44; 

...since I figure this must be some kind of "well-known address" and those are typically (though by no means always) read-only.

like image 151
T.J. Crowder Avatar answered Oct 06 '22 01:10

T.J. Crowder