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

Discussion in 'Programmer's Corner' started by embpic, Apr 18, 2014.

  1. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    hello master's
    what does this means (unsigned char *)&variable name.
     
  2. robvleugel

    New Member

    Oct 3, 2013
    4
    6
    &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.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    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: Apr 18, 2014
  4. embpic

    Thread Starter Member

    May 29, 2013
    187
    3
    sorry for late reply.
    Code ( (Unknown Language)):
    1.  
    2. 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 ???
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    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).
     
Loading...