what does this mean (unsigned char *)&variable name

&variable name is the memory address of the variable name, which you can store in a pointer. The parenthesis ( and ) are used to explicitly cast the pointer to a type of unsigned char pointer, in other words the resulting pointer is a pointer pointing to the size of an unsigned char on the memory address of variable name.
 

ErnieM

Joined Apr 24, 2011
8,377
To continue...

A char type is typically 8 bits wide and the smallest memory element accessible. Even wider word processors (16, 32 or 64 bit) will gladly "pretend" to operate on individual byte size quantities.

So "&anything" gives you the address of anything.

Casting (converting the type) to a "char *" (char pointer) means "give me a pointer to the very first byte of whatever you are pointing to."
 
Last edited:

Thread Starter

embpic

Joined May 29, 2013
189
sorry for late reply.
Rich (BB code):
address_variable = (unsigned char *)&variable_name
if variable_name is int/unsigned int then what value will be in address_variable ??
what should be data type of address_variable ???
 

ErnieM

Joined Apr 24, 2011
8,377
Irregardless of the declared type of variable_name, address_variable will point to the very first memory location of variable_name.

The data type of variable_name is pointer to character.

The type a pointer references is important when you increment or decrement the pointer. Those operations will be correct to point to the next element (they often skip more then 1 memory location).
 
Top