jweinst1
7/1/2017 - 6:06 PM

pointing to a union in c

pointing to a union in c

#include "stdio.h"

//addressing a spot in a union

union foo {
  int i;
  char c;
};

int main(void) {
  union foo tester;
  tester.i = 6;
  int* ipnt = &tester.i;
  printf("The address of the int union is %p\n", ipnt);
  *ipnt = 4;
  printf("The value has been changed to %d\n", tester.i);
  return 0;
}