Professional Documents
Culture Documents
Textual Data
Figure ( a ) shows the format string and the data values as parameters for the print
function. Figure (b) shows the formatting operation and the resulting text stream.
Figure demonstrates the input format string concept with a control string
having two fields (%c and %f ) . The first one defines that a character will he
inserted here ; the second defines that a real will be inserted there.
There are only three differences between the conversion codes for
input formatting and output formatting.
First, there is no precision in an input conversion specification. It is an
error to include a precision.
There is only one flag for input formatting, the assignment
suppression flag (*). The assignment suppression flag tells scanf that
the next input field is to be read but not stored. It is discarded.
S.Vaishnavi Programming for Problem solving 18
The third difference is the width specification ; with input formatting
it is a maximum, not a minimum width. Input Parameters
For every conversion specification there must be a matching
variable in the address list.
Addresses are indicated by prefixing the variable name with an
ampersand ( & ).
If the user signals that there is no more input by keying end of file
( EOF ) , then scanf terminates the input process.
if scanf encounters an invalid character when it is trying to convert
the input to the stored data type, it stops.
34 56 +
Scanf(“%d%d %c”,&n1,&n2,&op);
operands
2+3
operator
S.Vaishnavi Programming for Problem solving 23
An operator is a symbol that tells the compiler to perform specific
mathematical or logical functions. C language is rich in built-in
operators and provides the following types of operators −
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Misc Operators
== Checks if the values of two operands are equal or not. If yes, (A == B) is not true.
then the condition becomes true.
!= Checks if the values of two operands are equal or not. If the (A != B) is true.
values are not equal, then the condition becomes true.
> Checks if the value of left operand is greater than the value (A > B) is not true.
of right operand. If yes, then the condition becomes true.
< Checks if the value of left operand is less than the value of (A < B) is true.
right operand. If yes, then the condition becomes true.
>= Checks if the value of left operand is greater than or equal to (A >= B) is not true.
the value of right operand. If yes, then the condition
becomes true.
<= Checks if the value of left operand is less than or equal to (A <= B) is true.
the value of right operand. If yes, then the condition
becomes true.
T T—T
&& Called Logical AND operator. If both the (A && B) is false.
TF –T
operands are non-zero, then the condition
becomes true. F T –T
F F –F
| Called Logical OR Operator. If any of the two (A || B) is true.
operands is non-zero, then the condition
becomes true.
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
& Binary AND Operator copies a bit to the result if it (A & B) = 12, i.e., 0000 1100
exists in both operands.
| Binary OR Operator copies a bit if it exists in either (A | B) = 61, i.e., 0011 1101
operand.
^ Binary XOR Operator copies the bit if it is set in (A ^ B) = 49, i.e., 0011 0001
one operand but not both.
~ Binary One's Complement Operator is unary and (~A ) = ~(60), i.e,. -0111101
has the effect of 'flipping' bits.
60=0011 1100
00111100=60
01111000=120
11110000=240
A 0 0 1 1 1 1 0 0 60
B 0 0 0 0 1 1 0 1 13
A&B 0 0 0 0 1 1 0 0 12 00111100=60
00011110=30
A|B 0 0 1 1 1 1 0 1 61 00001111=15
A^B 0 0 1 1 0 0 0 1 49 00000111=7
A<<2 1 1 1 1 0 0 0 0 240 00000011=3
A>>2 0 0 0 0 1 1 1 1 15
Assignment Operators
The following table lists the assignment operators supported by the C
language
& Returns the address of a &a; returns the actual address of the
variable. variable.
operand operator
Example:
• Function Call
sum(), area()
operator operand
Variable
In prefix expressions, the operator comes before the operand
Example:
• prefix Increment/Decrement (++,- -)
++a, --a
If ++ is after the operand, as in a++, the increment takes place after
the expression is evaluated. If ++ is before the operand , as in ++a,
the increment takes place before the expression is evaluated.
operator operand
• (2+(3*4))
• -b++ (if b=5)
Right-to-left Associativity
a += b *= c -= 5
If a=3,b=5, c=8
then it is evaluated to 18
(a = 3 + (b = (5 * (c = 8 - 5)))