0
How i got this ans explain please i want to know how 1 i got in printf ("%d", p<q) ;
5 Réponses
+ 1
Habit 🧐 p is not pointing to a[4] and q to a[2] ,they are still pointing to the a[1] for p and a[5] for q ,
Doing this operation => *(p+3) doesn't actually makes the pointer assign new location ,it just adds to address 3 values and gets the item from there
+ 1
Habit 🧐 I made some edit, you aren't actually moving the pointer but you are just getting it's address and adding to it 3 and using * gets the value from that location
0
#include <stdio.h>
int main()
{
int a[]={5,16,7,89,45,32,23,10};
int *p= &a[1],*q=&a[5];
// *p points to 16, *q points 32
printf ("%d\n",*(p+3)); // *(p+3) return 45 that is a[4]
printf ("%d\n",*(q-3)); // *(q-3) return 7 that is a[2]
printf ("%ld\n",q-p); // q points to 5th element in array p points to 2nd elementin array , (q-p) return number of elements *int size
printf ("%d",p<q); //p is first location ,q is next location p<q true
printf ("%d",*p<*q); //16<32
return 0;
}
Edit:
@Habit
it's pointing to next location by calculation. But its not updating pointers locations...
0
But p now a[4] and q now a[2] than how is true and 16 <32 true (1)? 🙄
0
Now i understand thanks 🤪