The relational operators are 

   >   >=   <   <=
They all have the same precedence. Just below them in precedence are the equality operators: 

   ==   !=
Relational operators have lower precedence than arithmetic operators, so an expression like i < lim-1 is taken as i < (lim-1), as would be expected. 
More interesting are the logical operators && and ||. Expressions connected by && or || are evaluated left to right, and evaluation stops as soon as the truth or falsehood of the result is known. Most C programs rely on these properties. For example, here is a loop from the input function getline that we wrote in A Tutorial Introduction

   for (i=0; i < lim-1 && (c=getchar()) != '\n' && c != EOF; ++i)        s[i] = c;
Before reading a new character it is necessary to check that there is room to store it in the array s, so the test i < lim-1 must be made first. Moreover, if this test fails, we must not go on and read another character. 
Similarly, it would be unfortunate if c were tested against EOF before getchar is called; therefore the call and assignment must occur before the character in c is tested. 
The precedence of && is higher than that of ||, and both are lower than relational and equality operators, so expressions like 

   i < lim-1 && (c=getchar()) != '\n' && c != EOF
need no extra parentheses. But since the precedence of != is higher than assignment, parentheses are needed in 

   (c=getchar()) != '\n'
to achieve the desired result of assignment to c and then comparison with '\n'. 
By definition, the numeric value of a relational or logical expression is 1 if the relation is true, and 0 if the relation is false. 
The unary negation operator ! converts a non-zero operand into 0, and a zero operand in 1. A common use of ! is in constructions like 

   if (!valid) rather than 

   if (valid == 0)
It's hard to generalize about which form is better. Constructions like !valid read nicely (``if not valid''), but more complicated ones can be hard to understand. 
Revison. Write a loop equivalent to the for loop above without using && or ||. 

0 comments:

Post a Comment

 
  • Symbolic Constants

    What Is The Variables and Arithmetic Expressions The next program uses the formula oC=(5/9)(oF-32) to print the following table

  • Navigation For Blogger New Script

    Today we will see how to add a nice page number navigation hack blogger. The default navigation links (i.e Older Posts) is not the friend

  • How To Creat Facebook Fantasty Box

    Fantasty Look Custom Facebook Like Box To Blogger Facebook Like Box is very useful widget to show visitors the authority and love of t

  • Basic Knowladge Of Computer

    Computer is an electronic device that accepts the data from any Input Device process them according to instruction and gives the Output.Computer is an electronic device that..

  • Earn Money To Easy Way

    HI MEMBER, FIRST OF ALL HEARTY WELCOME TO OUR COMPANY.FIRST TIME IN THE WORLD WE ARE INTRODUCING A STEP BY STEP TRAINING PROCESS TO MAKE MONEYMAKE MONEY ONLINE

Top
Blogger Template - See more at: http://www.arya2014.blogspot.in
ONLINE EDUCATION Basic Computer Application EARN MONEY TO EASY WAY Make Money Online "C" PROGRAMING Introducing "C" Language