Home > other >  invalid operands to binary - (have 'int *' and 'int **')
invalid operands to binary - (have 'int *' and 'int **')

Time:12-06

#include<stdio.h>
void main()
{
int a[]= {10,20,30,40,50,60};
int *p[]= {a,a 1,a 2,a 3,a 4,a 5};
int **pp=p;
pp  ;
printf("%d,%d,%d", pp-p,*pp-a, **pp);
*pp  ;
printf("%d,%d,%d", pp-p, *pp-p, *pp-p);
  *pp;
printf("%d,%d,%d", pp-p, *pp-a, **pp);
  **pp;
printf("%d,%d,%d", pp-p, *pp-a, **pp);
}

it's showing this error:

invalid operands to binary - (have 'int *' and 'int **')
     printf("%d,%d,%d", pp-p, *pp-p, *pp-p);
 invalid operands to binary - (have 'int *' and 'int **')
     printf("%d,%d,%d", pp-p, *pp-p, *pp-p);

CodePudding user response:

*pp-p, you cannot subtract a int** from an int* since they are not compatible types. It should be pp-p.

Also please note that in order to print addresses with printf, you should cast the pointers to void* and print using %p.

  • Related