next up previous contents index
Next: Structures and subroutines Up: Structures Previous: Defining structures   Contents   Index

Pointers to structures

One can use structures in the same ways as other basic data types. This includes making pointers to structures. With pointers, though, in accessing structure members an arrow notation is used, rather than the dot notation:
#include <stdio.h>
typedef struct {
  int n, d;
} frac;
int main(void) {
  frac *f1;
  f1 = (frac *) malloc(sizeof(frac));
  f1->n = 1;
  f1->d = 3;
  printf("The fraction is %d / %d\n", f1->n, f1->d);
  return 0;