B) Introduction To C++
B) Introduction To C++
TRUE FALSE
FALSE TRUE
ASSIGNMENT OPERATORS
It is used to assign either a
value or an expression to a variable.
Syntax :
variable= value or expression;
Example :
n=10; assigns or stores the
value 10 in the variable ‘n’.
Sum = a +b;
SHORT-HAND OPERATORS
These operators are used to reduce the length of the operation
and represent it in a shorter form in a program. It is also used as an
assignment operator. Few shorthand operators are
▀ +=
C+=5 is equivalent to C=C+5
▀ -=
C-=5 is equivalent to C=C-5
▀ *=
C*=5 is equivalent to C=C*5
▀ /=
C/=5 is equivalent to C=C/5
▀ %=
C%=5 is equivalent to C=C%5
BITWISE OPERATORS
These allows us to perform various
operations on the individual bits of a
memory location. The bitwise operators
are:
Bitwise AND (&)
Bitwise OR (|)
Bitwise XOR (^)
Bitwise NOT (one’s complement) (~)
Bitwise left shift (<<)
Let a = 00111 and b = 01010
Operator Description Example
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Operator Description Example
It reverses the values of all the bits i.e. all 1’s ~a gives 11000
~ (ones) present in the number are changed to
0’s (zeroes) and all the 0’s (zeroes) are
changed to 1’s (ones).
It shifts each bit in the operand to the left. The a<<3 gives 11000
<< number of places the bits are shifted depends
on the number following the operand.
It shifts each bit in the operand to the right. a>>2 gives 00001
>> The number of places the bits are shifted
depends on the number following the
operand.
TERNARY OPERATOR
Ternary operators are those operators
that operate on three operands. It is also
called as conditional operator. The ternary
operator acts like a shorthand version of the
if-else construct.
Syntax
variable = exp1?exp2 : exp3;
If exp1 is true, exp2 is evaluated,
otherwise exp3 is evaluated.
Example
Large = (a>b) ? a : b;
SPECIAL OPERATORS
, Links the related
expressions together
. Direct member selection
→ Indirect member selection
sizeof () It returns the size of a
variable
1 MARK QUESTIONS
1)What is an operator?
2)What is an operand?
3)What is meant by unary operator?
4)Mention the different unary
operators.
5)What is a binary operator?
6)Mention the different binary
operators.
7)Mention the different arithmetic
operators.
8)What is the difference between /
11)When is logical operator used?
12)Mention the different logical operators.
13)What is the purpose of assignment operator?
14)Write the syntax of assignment operator.
15)What is the purpose of the short-hand
operator?
16)What is the purpose of the bitwise operator?
17)Mention the different bitwise operators.
18)What is ternary operator?
19)What is the other name for the ternary
operator?
20)Write the syntax of ternary operator.
3 MARK QUESTIONS
1) Explain logical operators.
2) Explain assignment operator.
3) Explain ternary operator.
5 MARK QUESTIONS
4) Explain unary operators.
5) Explain arithmetic operators.
6) Explain relational operators.
7) Explain bitwise operators.