1 #include <stdio.h> 2 #include <io_utils.h> 3 4 int main() { 5 { 6 int a = 2; 7 int *p = &a; 8 9 PRINT_INT(p + 1); 10 PRINT_INT(p); 11 PRINT_INT(sizeof(int)); 12 } 13 14 { 15 double a = 2.0; 16 double *p = &a; 17 18 PRINT_INT(p + 1); 19 PRINT_INT(p); 20 PRINT_INT(sizeof(double )); 21 } 22 23 { 24 double a = 2.0; 25 double *p = &a; 26 double **pp = &p; 27 28 PRINT_INT(pp + 1); 29 PRINT_INT(pp); 30 PRINT_INT(sizeof(double *)); 31 } 32 { 33 int array[] = {0, 1, 2, 3, 4}; 34 PRINT_INT(array); 35 int *p = array; 36 PRINT_INT(*(p + 3)); 37 PRINT_INT(*(array + 3)); 38 PRINT_INT(*(3 + array)); 39 PRINT_INT(3[array]); // not recommend 40 PRINT_INT(array[3]); 41 PRINT_INT(p[3]); 42 43 int *const array_p = array; 44 45 PRINT_BOOL(p + 3 > p + 1); 46 PRINT_BOOL(p + 3 == p + 3); 47 48 int array2[] = {3,4}; 49 int *p2 = array2; 50 PRINT_BOOL(p + 3 == p2 + 1); // meaningless 51 PRINT_BOOL(p + 3 > p2 + 1); // meaningless 52 } 53 return 0; 54 }
运行结果
指针比较 是比较连续的地址空间才有意义,要不没有意义。 像50,51 行代码,其实就是没意义的
标签:运算,INT,double,C语言,int,BOOL,PRINT,array,指针 From: https://www.cnblogs.com/liumy/p/17091389.html