#include <stdio.h>
#include <cstring>
#include <stdlib.h>
#include <cmath>
int main()
{
int * pn1,*pn2;
int n=4;
char *pc1,*pc2;
pn1 = (int *)100;
pn2 = (int *)200;
printf("%d\n",pn2-pn1); //(200-100)/4
pc1 = (char *)pn1;
pc2 = (char *)pn2;
printf("%d\n",pc1-pc2);//100-200/1 = -100
printf("%d\n",(pn2+n)-pn1); //(200+4*4-100)/4 = 29
int *pn3 = pn2 + n;
printf("%d\n",pn3-pn1); //29
printf("%d\n",(pc2-10)-pc1);//90
return 0;
}
#include <cstring>
#include <stdlib.h>
#include <cmath>
int main()
{
int * pn1,*pn2;
int n=4;
char *pc1,*pc2;
pn1 = (int *)100;
pn2 = (int *)200;
printf("%d\n",pn2-pn1); //(200-100)/4
pc1 = (char *)pn1;
pc2 = (char *)pn2;
printf("%d\n",pc1-pc2);//100-200/1 = -100
printf("%d\n",(pn2+n)-pn1); //(200+4*4-100)/4 = 29
int *pn3 = pn2 + n;
printf("%d\n",pn3-pn1); //29
printf("%d\n",(pc2-10)-pc1);//90
return 0;
}