Make the pointer look like its pointing to desired address

hi,
First let me post a code here to make my question clear.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

int main()
{
  unsigned int *ptr;
  int val = 150;
  ptr = &val;
  cout << "pointer location is: " << ptr <<endl;
}



The code above displays a hex address pointed by the pointer, "otr". But for my code i wanted it to look like it is pointing from location 0 to 150, without changing the actual value of the pointer "ptr". Is there a way that i can achieve this?
Last edited on
1
2
3
ptr = &val;
for(unsigned int I = 0; I <= ptr; I++)
   std::cout << I << std::endl;

?

BTW, ptr does not hold a value of 150. That is the value of val. ptr's value is whatever memory address val is at, and *ptr holds the value 150.
It points to the memory address AFAIK but you can change the pointed address's value by something like this
1
2
3
short value = 10 , *ptr = &value;
*ptr++;
std::cout << value << std::endl;
Last edited on
ok... Thanks....
Topic archived. No new replies allowed.