指针减指针

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> int main(void) { // 两个同类型的指针相减 返回值是个有符号的整数 int sz[5] = {1, 2, 3, 4, 5}; int *p1 = &sz[1]; int *p2 = &sz[4]; int d = p1 - p2; // 数组分配的是连续的内存 printf("p1的值为: %p\n", p1); printf("p2的值为: %p\n", p2); printf("d 的值为: %d\n", d); // // system("cc --version"); // int a1; // scanf("%d",&a1); /** int a = 10; int b = 20; int *pa = &a; int *pb = &b; // int d = *pa-*pb; int d = pa - pb; // 值会随着两个变量之前内存分配不同,而结果不同 printf("%p\n", pa); printf("%p\n", pb); printf("%d", d); **/ return 0; }
Editor Settings
Theme
Key bindings
Full width
Lines