How to store some value at any desired address?

Showing Answers 1 - 10 of 10 Answers

vipin gupta

  • Oct 30th, 2006
 

Be carefull !! U should not overwrite the addres used by OS or some other processes......Its not a good programming practice to write data on the address specified in ur program.
However, here is the code to do so ....
int *ptr = ANY_ADDRESS; // any address at which u want to store value;
*ptr = ANY_VALUE; // value u want to store at above location;

  Was this answer useful?  Yes

raveesh

  • Nov 25th, 2006
 

    we can  put any desired address in a pointer( by declaring with it's data

     type of value which it contain).

      and after aasigning  address to pointer we can put any value in this 

      pointer.

            GENERALLY  IT WILL OVERWRITE  ON ANY DATA WHICH HOLD

            SAME ADDRESS WHERE WE ASSIGNED OVER DESIRED ADDRESS.

             --it is used in TSR  technique.        

  Was this answer useful?  Yes

Vivek Bhadra

  • Jan 4th, 2007
 

Hi ,

         I think whenever you wanna write some data in a memory address or say data buffer mae sure it doesn't invoke any race condition. To ensure the integrity of the data at certain memory address OS provides lots many options as Semaphores, mutex Spinlocks etc. Depending upon ur os the code may look quite like the following :

data_type *ptr = Address_value(or say buffer address);

semaphore_wait( BufferWrite_Sem);

*ptr = value you wanna put;

semaphore_signal( BufferWrite_Sem);

If you r using a semaphore mak sure ur r properly signalling it otherwise the whole program may get blocked.

  Was this answer useful?  Yes

Dhanush

  • Jul 9th, 2019
 

Segmentation fault (core dumped)

Code
  1. #include<stdio.h>

  2. int main()

  3. {

  4.         int *p;

  5.         p=( int *)(0x500000);

  6.         *p=123;

  7.   printf("%d",*p);

  8.         printf("value is stored in an address %u

  9. ",*p);

  10. }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions