Pointer Comparison Operation in C

Notes:

Pointer Comparison Operation in C Programming Language:

4. Comparison Operations: Pointer comparison operations in C
- If two pointer variables are of same type, then they can be compared with one another
- To compare pointer variables; we take help of comparison or relational operators in C

W.K.T. There are 6 comparison or relational operators in C; they are ==, !=, <, >, <= and >=

ptr1 == ptr2:
- is used to check whether two pointer variables are having the address of same memory location
- is used to check whether two pointer variables are pointing to the same memory location

ptr1 != ptr2:
- is used to check whether two pointer variables are not having the address of same memory location
- is used to check whether two pointer variables are not pointing to the same memory location

ptr1 < ptr2:
- is used to check whether value of ptr1 is less than the value of ptr2
- is used to check in the memory whether the memory location pointed by ptr1 appears before the memory location pointed by ptr2

ptr1 > ptr2:
- is used to check whether value of ptr1 is greater than the value of ptr2
- is used to check in the memory whether the memory location pointed by ptr1 appears after the memory location pointed by ptr2

ptr1 <= ptr2:
- is used to check whether value of ptr1 is less than or equal to the value of ptr2
- is used to check in the memory whether the memory location pointed by ptr1 appears before the memory location pointed by ptr2 or both are pointing to same memory location

ptr1 >= ptr2:
- is used to check whether value of ptr1 is greater than or equal to the value of ptr2
- is used to check in the memory whether the memory location pointed by ptr1 appears after the memory location pointed by ptr2 or both are pointing to same memory location