Invalid type argument of unary ‘*’ (have ‘int’) Error in C

You forgot to make p and q int pointers. Also, you forgot to use the format specifier in the printf statements. Try the following:

#include <stdio.h>
#include <stdlib.h>

/*
* 
*/
int main() {
  int a[] = {5, 15, 34, 54, 14, 2, 52, 72};
  int *p = &a[1];
  int *q = &a[5];   

  printf("%d\n", *(p+3));
  printf("%d\n", *(q-3));
  printf("%d\n", *q-*p);
  printf("%d\n", *p<*q);
  return (EXIT_SUCCESS);
}

Leave a Comment