Chapter 2 LQ
Chapter 2 LQ
USER INTERACTION
1. What are logical operators?
Definition:
“The operators that are used to combine two or more conditions (relational expressions) are
called logical operators.”
They result in true or false.
The true is represented by 1 while false is represented by 0.
There are three types of logical operators in C.
Description Operators
AND &&
OR ‖
NOT !
(i) Logical AND operator:
“The operator that takes two operands as input and produces a result true if both operands are true is
called AND operator.”
Representation:
It is represented by “&” symbols.
Truth Table:
Following is a truth table of AND operator:
Expression Result
False && False False
False && True False
True && False False
True && True True
(ii) Logical OR operator:
“The operator that takes two operands as input and produces a result true if any of the operands is
true and returns false if both operands are false is called OR operator.”
Representation:
It is represented by ‖ symbols.
Truth table:
Following is a truth table for the OR operator:
Expression Result
False ‖ False False
False ‖ True True
True ‖ False True
(iii) Logical NOT operator:
“The operator that indicates or reverses the result of a condition is called NOT operator.”
Representation:
The operator is represented by the “!” sign.
Truth Table:
The truth table of logical NOT operator is as follows:
Expression Result
False True
True False
2. What is the scanf ( ) function? Explain with the help of examples.
This function is used to take input from the user into the variable. It is a built-in standard input function of
the C language. The standard input means the input from the keyboard. This function is pronounced as
scan-eff.
Elements:
There are two main parts of the scanf function.
The first part inside the double quotes is a list of format specifiers.
The second part is the list of optional variables with & sign at their left.
Ampersand & sign:
The ampersand & sign is called the address of operator. If this sign is missed then the value cannot be
stored in the given variable.
While reading input from the keyboard it waits for the enter key after each character. it also allows us
to take multiple inputs in a single scanf statement. This function is declared in <stdio.h> header file.
Syntax:
scanf ("format specifier", &variable list);
scanf ("%d, &X);