Computer Science, asked by puneethk3960, 6 months ago

The------------statement allows a program to make a decision based on the truth or falsity of some condition.

Answers

Answered by kulkarninishant346
1

Boolean Variables and Data Type ( or lack thereof in C )

A true boolean data type could be used for storing logical values, and would only have two legal values - "true", and "false".

C does not have boolean data types, and normally uses integers for boolean testing.

Zero is used to represent false, and One is used to represent true.

For interpretation, Zero is interpreted as false and anything non-zero is interpreted as true.

To make life easier, C Programmers typically define the terms "true" and "false" to have values 1 and 0 respectively.

In the old days, this was done using #define:

#define true 1

#define false 0

Today it is better to use const int instead of #define:

const int true = 1;

const int false = 0;

C99 provides a new header, stdbool.h, that defines some new helpful types and constants:

The type "bool" is the same as a newly defined type "_Bool"

_Bool is an unsigned integer, that can only be assigned the values 0 or 1

Attempting to store anything else in a _Bool stores a 1. ( Recall that C interprets any non-zero as true, i.e. 1 )

Variables can now be declared of type "bool".

stdbool.h also defines constants "true" and "false", with value 1 and 0 respectively.

Use these new features using #include <stdbool.h> at the top of your program

Relational Operators

Relational operators are binary operators that evaluate the truthhood or falsehood of a relationship between two arguments, and produce a value of true ( 1 ) or false ( 0 ) as a result.

The following table shows the 6 relational operators and their meaning, by example:

Operator

Meaning

A > B

True ( 1 ) if A is greater than B, false ( 0 ) otherwise

A < B

True ( 1 ) if A is less than B, false ( 0 ) otherwise

A >= B

True ( 1 ) if A is greater than or equal to B, false ( 0 ) otherwise

A <= B

True ( 1 ) if A is less than or equal to B, false ( 0 ) otherwise

A = = B

True ( 1 ) if A is exactly equal to B, false ( 0 ) otherwise

A != B

True ( 1 ) if A is not equal to B, false ( 0 ) otherwise

( Note: There should not be a space between the two equals signs in = =. I am adding one in these HTML notes so the two signs do not run together, as ==. )

DANGER DANGER: Do not confuse the equality test operator, = =, with the assignment operator, =. It is a VERY common error to use the wrong number of equals signs, ( either too many or too few ), and the resulting code will usually compile and run but produce incorrect ( and often unpredictable ) results.

Example: "while( i = 5 )" is an infinite loop, because i is given the value 5 by the assignment, and since this is non-zero, it is always true. The programmer probably meant to use "while( i = = 5 )", which will test whether or not i is equal to 5, and will only continue to loop as long as this is true.

<, <=, >, and >= have equal precedence, higher than = = and !=, which have equal precedence with each other. All these operators are evaluat

Similar questions