The C relational expression evaluation of the logical operators program example

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: The C relational expression evaluation of the logical operators program example

To show: How to construct and use the C relational expressions and logical operators

 

 

// Demonstrate the evaluation of relational expressions

#include <stdio.h>

 

int main(void

{

int a;

 

// Evaluates to 1, TRUE

a = (5 == 5);

printf ("\na = (5 == 5)\n Then a = %d\n", a);

 

// Evaluates to 0, FALSE

a = (5 != 5);

printf ("\na = (5 != 5)\n Then a = %d\n", a);

 

// Using operator precedence

// Evaluates to 1 + 1, TRUE

a = (12 == 12) + (5 != 1);

printf("\na = (12 == 12) + (5 != 1)\n Then a = %d\n", a);

 

return 0;

}

 

Output example:

 

a = (5 == 5)

Then a = 1

a = (5 != 5)

Then a = 0

a = (12 == 12) + (5 != 1)

Then a = 2

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index