Is this the way that we should compare two pointers?. Should we not use
void* pointer for a comparision?
You can always compare two object pointers of like type which point to
(parts of) the same object. For example, two pointers to 'int' can be
compared with '>' if they both point into the same array. Or you can
compare two pointers to 'char', or two void pointers. (There are other
rules: for example, IIRC you can compare a void pointer to any other
object pointer; but that's not nearly as important as the basic rule.)
buf1, buf2 are int* and "Downwards" : "Upwards" are string.
Correct. Notice that the comparison of 'buf1' and 'buf2' is illegal,
because while they have the right types, they don't point to comparable
addresses --- they point to two different malloc'ed blocks of memory.
The OP "forces" no conversion. Is he making a implicit conversion.
No. Both values are of type 'pointer to int' already; no conversions
take place.
The expression evaluates 'buf1 > buf2' (which is undefined, but let's
pretend it returns 0 or 1 like a normal comparison), and then yields
either "Downwards" (an array[10] of char) or "Upwards" (an array[8] of
char). In either case, the array of char /decays/ to a pointer to char,
which is then passed to 'printf'. 'printf' takes the string and prints
it on the screen. No conversions happen except for the array-to-pointer
decay, and that's nothing special.
HTH,
-Arthur