what can be done with this?
what can be done with this?
That really depends on the hardware, and whatever OS lies between your program and the "bare metal".
If you're on a simple PIC/AVR for example, and writing say 0x55 to a memory location causes a row of 8 LED's to alternately light up, then that's one end of the spectrum.
If you're on a regular desktop with an OS that gives each user process a virtualised environment, then you have to rely on the OS to give you a specific API to do specific things to the hardware. For example, you can write to a disk via the file system, but you can't just randomly choose a sector and scribble anything you want. You can do a bit more damage with 'root' privileges, but you're still somewhat constrained by what the OS drivers may allow you to do.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Anything and nothing.
Anything in the sense that, with a pointer of an appropriate value, it is possible to communicate directly with hardware. Of course, you have to know the actual addresses that a given piece of hardware uses to communicate. Specifically, if you are attempting to send data or commands to a particular item of hardware, then you need to know what memory locations (if any) that hardware listens to. Similarly, if you are attempting to receive data from a particular item of hardware, you need to know what memory locations (if any) that hardware writes data to. You also need to know the meaning of particular data at that specified memory location, in order to either make a meaningful request or to interpret the response.
Nothing in the sense that there is more to communicating with hardware than stuffing data into, or sucking data from, a memory location - which is all that is really possible with pointers. Not all hardware communicates through memory locations that are accessible via pointers. Modern operating systems (windows, unix, etc) are specifically designed to prevent software from directly communicating with hardware - it is necessary to use some API or other means to make a request of the operating system which, if it so chooses, then passes the request onto the relevant hardware. Because of that, software that attempts to manipulate hardware in untoward ways often finds itself being stopped (for example, modern operating systems routinely terminate program that are detected in an attempt to access a memory location it shouldn't).
>what can be done with this?
It’s like asking I’ve got bread and butter, what can I do with it?
Well, the one powerful use of pointer is that, it can point anywhere in the memory to either read and write (assuming that intermediate OS not in use, like in some embedded systems). There are set of GPIO devices which might be mapped to a processor register, writing to those registers is literally altering power levels at the target GPIO devices. At the any of the day, anything you want to control through program would have been connected to some sort of registers which either your program writes directly to the registers or you memory map the register to a memory block. Writing to the memory block which in turn writes it to the registers, resulting in some action taking place on the connected hardware.
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein