This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Using Pointer

Please could some body take a look at
my code to see why the Pointer variables
do not display correctly using debug in
Uvision2.

Here is the code:

unsigned int xdata VALUE;
unsigned int xdata *addr = &VALUE;

Main()
{
for (VALUE=1; VALUE<=10; VALUE++)
{
printf("VALUE = %d", *addr); //data
pritnf("addr1 = %d", addr); //address1
printf("addr2 = %d", &VALUE); //address2
}
}

/////////////// end //////////////

PROBLEM: VALUE at printf statement line1
works properly, but the remaining two
printf statements for printing ADDRESS1, and ADDRESS2 are always displaying 256




Parents
  • Please read the "Tips for Posting Messages" before you post a message - particularly the bit about using 'pre' and '/pre' tags when posting source code!

    addr and &VALUE are pointers, but the %d printf format expects an int - you can't expect to get the right results if you supply the wrong sort of argument!

    Go back to the manual and carefully read the sections on pointers and the printf formats.

Reply
  • Please read the "Tips for Posting Messages" before you post a message - particularly the bit about using 'pre' and '/pre' tags when posting source code!

    addr and &VALUE are pointers, but the %d printf format expects an int - you can't expect to get the right results if you supply the wrong sort of argument!

    Go back to the manual and carefully read the sections on pointers and the printf formats.

Children