473,242 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

Comparing Pointer

Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?
Oct 16 '06 #1
3 9580
se***************@gmail.com wrote:
Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?
Yes, but with limitations. You're allowed to compare any two valid or
null pointers of compatible types[1] using == and !=. Using <, >, <= and
>=, though, there is the additional demand that they must point within
the same object (array, struct, union, etc.). If not, the behaviour is
undefined. That also means that you can't compare to a null pointer
(constant) using < or >.

Richard

[1] Or pointers to void, or pointers to qualified versions of compatible
types, or null pointer constants.
Oct 16 '06 #2
se***************@gmail.com writes:
Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?
If your textbook doesn't answer that question, get a better one. I
recommend K&R2 (Kernighan & Ritchie, _The C Programming Language_, 2nd
Edition).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 16 '06 #3
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>se***************@gmail.com writes:
>Does anybody know if it is allowed to compare pointer using the
operators '<', '<=', '>' or '>='?

If your textbook doesn't answer that question, get a better one. I
recommend K&R2 (Kernighan & Ritchie, _The C Programming Language_, 2nd
Edition).
In some prints of the book, the section on pointer comparisons
(A7.10) has an omission that is corrected in the errata, see
http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html .
Oct 17 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
6
by: Pierre McCann | last post by:
Hello: I am writing the following program in C, but I do most of my coding in C++, and am not intimately familiar with the C notation for pointers. As such, I am trying to do a comparison...
3
by: Mark Denardo | last post by:
Hi I have an app that has a number of textboxes (richtextboxes to be exact) that get created dynamically and I add a few at a time to panel controls (so I can flip a group in and out when I want). ...
5
by: ma740988 | last post by:
There's a need for me to move around at specified offsets within memory. As as a result - long story short - unsigned char* is the type of choice. At issue: Consider the case ( test code ) where...
12
by: barcaroller | last post by:
Is it legal to compare the contents of two multi-field variables (of the same struct) using "==" and "!="? struct { int a; int b; } x,y; ...
20
by: Bill Pursell | last post by:
This question involves code relying on mmap, and thus is not maximally portable. Undoubtedly, many will complain that my question is not topical... I have two pointers, the first of which is...
9
by: subramanian100in | last post by:
Suppose we have char *a = "test message" ; Consider the comparison if (a == "string") ..... Here "string" is an array of characters. So shouldn't the compiler
10
by: william | last post by:
#include <stdio.h> int main() { char *str=NULL; char x="today is good!"; printf("%s", str); str=strtok(x," "); if (str=="today") //<==here is line that confuses me printf("they equals!\n");
25
by: J Caesar | last post by:
In C you can compare two pointers, p<q, as long as they come from the same array or the same malloc()ated block. Otherwise you can't. What I'd like to do is write a function int comparable(void...
7
by: arnuld | last post by:
On Mon, 28 Apr 2008 07:25:53 +0000, Richard Heathfield wrote: Either you are not understanding me or I am not able to understand this <p_strcmpthing. This is your code:
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.