I would like to ask why the pointer can be compared with another pointer. I have
ID: 3719039 • Letter: I
Question
I would like to ask why the pointer can be compared with another pointer. I have tried the cout pointer and will have an address like 00fe765rx8. Do not understand how to compare, I do not understand why the example appears 0
Pointer arithmetic and expressions Pointer assignment . Pointer can be assigned to another pointer Both pointers MUST be of the same type ptr2 ptr1; // ptr2 points to the same // location as ptr1 does Pointer comparison (by equality or relational operator) sCompare addresses stored in pointers Meaningless unless pointers point to elements of the same array Examples if (pt r1 == 0) { if (ptr2> ptr1) } // if ptrl is0 (null pointer) > // if ptr2 has a higher indexExplanation / Answer
Pointer Arithmetic allows us to treat the pointer as a normal variable in some way.
Consider following example code:
int arr[]={1 2 3 4 5};
int *ptr1,*ptr2;
ptr1=arr;
ptr2=0;// 0 is null pointer constant
currently ptr1 pointing to first element of arr i.e 1
Pointer arithmetics operations:
Also you are trying to print pointer directly that why you are getting address like 00fe765rx8 using * while printing so that you can print content to which pointer is pointing to.
thumbs up if you are satisfied with the answer otherwise reply with your concern.