CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Ketan Lalcheta
#include <iostream>
int main()
{
int x = 4;
int y = 5;
int* x_ptr = &x;
int* y_ptr = &y;
// the diff btw two pointers computed as pointer difference
std::ptrdiff_t ptr_diff = x_ptr - y_ptr;
std::cout << x_ptr << std::endl;
std::cout << y_ptr << std::endl;
std::cout << ptr_diff << std::endl;
// the diff btw two pointers computed as integer difference
std::intptr_t diff = (std::intptr_t)x_ptr - (std::intptr_t)y_ptr;
std::cout << diff << std::endl;
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run