ADDRESS-OF

the address-of operator returns the memory address of its operand. it can also be used to assign values to memory variables

USAGE: DISPLAYING ADDRESS VALUES

#include <stdio.h>

int main(int argc, char* argv[])
{
  int intergerVariable = 100;
  double doubleVariable = 2.71828;
  
  printf("Address of integerVariable is %p\n", &integerVariable);
  printf("Address of doubleVariable is %p\n", &doubleVariable);
}

 * the %p format specifier is used to output ponter values (addresses)

 * OUTPUT:
    Address of integerVariable is 0x7fffe74c2dd4
    Address of doubleVariable is 0x7fffe74c2dd8

USAGE: ASSIGNING ADDRESS VALUES

#include <stdio.h>

int main(int argc, char* argv[])
{
  int integerValue = 100;
  double doubleValue = 2.71828;
  int* pIntegerValue = &integerValue;
  double* pDoubleValue = &doubleValue;
  
  printf("Pointer to integerValue (pIntegerVariable): %p: Address of integerVarible: %p\n", pIntegerVariable, &pIntegerVariable);
  printf("Pointer to doubleValue (pDoubleVariable): %p Address of doubleVariable: %p\n", pDoubleVariable, &doubleVariable);
  
  return 0;
}

 * OUTPUT:
    Pointer to int1 (p_int1): 0x7ffff7d374a4: Address of int1: 0x7ffff7d374a4
    Pointer to doub1 (p_doub1): 0x7ffff7d374a8 Address of doub1 is 0x7ffff7d374a8

Last updated