Welcome to pickSourcecode.com Login | Register    
pickZy.com
 Home  | search  | games  | General  | C  | C++  | Java  | Php  | Networking  | Visual Basic  | VC++  | Win32  | MFC  | JavaScript  | Jobs  | JavaScript  | Post jobs
C - Relational and logical operators       Share
2007-08-29 |  RatheeshTR  | Viewed: 559  |    0


Relational operators:


When we previously talked about conditions in if statements, we said that conditions are built out of relational and logical operators. We described the six relational operators that C provides for comparing numbers:


== != > < >= <=


But suppose you need to know if the value of the variable x is both greater than zero and less than one? None of these relational operators by itself can answer that question. What you need is to combine two conditions:

(x > 0.0) and (y < 1.0)

C Logical Operators:

This is what logical operators can do for you. A logical operator combines one or two conditions into a single new condition. C provides three logical operators:

* ``&&'' (two ampersands) means and.
* ``||'' (two vertical bars) means or.
* ``!'' (an exclamation point) means not.

Let's look at an example. If you need to know if the value of the variable x is between zero and one, inclusive, you would write this:

if ((x >= 0.0) && (x <= 1.0))
...
if ((x == 0) || (y == 1 )



Latest topics
C - Arrays of structures  Viewed: 285
C - structures and functions  Viewed: 292
tcpdump by host name or ip  Viewed: 292
C - pointers and Arrays  Viewed: 295
C - File Access  Viewed: 295
C - For loop statements  Viewed: 296
C - pointers to pointers  Viewed: 296
C - Register variables  Viewed: 297
C - Static variables  Viewed: 299
C - Pass-by-reference parameters  Viewed: 300

Comments:





Submit comment's

Type:

User Comment's:

Submitted By:
Prof: Software Engineer
Tech: C ,Cpp
Send Mail: ratheesh



Related topics
C - Functions and program structure, Programmed pass-by-reference via pointers, Pass-by-reference parameters
C - Pass-by-reference parameters
C - pass-by-reference via pointers

Related References
c - swap num, pass-by-reference parameters
c - pass-by-reference via pointers

Web site contents © Copyright 2007, All rights reserved.
Help | Terms and Conditions | Privacy Policy | About Us