Adding long values ​​shows different o / p values

I encountered a problem while adding long values ​​Example

typedef unsigned short UINT16; UINT16* flash_dest_ptr; // this is equal to in hexa 0XFF910000 UINT16 data_length ; // hex = 0x000002AA & dec = 682 //now when I add UINT16 *memory_loc_ver = flash_dest_ptr + data_length ; dbug_printf( DBUG_ERROR | DBUG_NAVD, " ADD hex =0x%08X\n\r",memory_loc_ver ); 

Actual O / p = 0xFF910554

 // shouldn't o/p be FF9102AA ? 
+4
source share
2 answers

Pointer arithmetic therefore

 UINT16 *memory_loc_ver = flash_dest_ptr + data_length ; 

advances flash_dest_ptr by data_length * sizeof (UINT16) bytes.

Typically, sizeof (UINT16) will be 2, and

 2 * 0x2AA = 0x554 
+5
source

When you add integers to the pointer value, you actually move the pointer as much as it would take to move the data_length UINT16 in memory, not data_length bytes.

0
source

Source: https://habr.com/ru/post/1480161/


All Articles