Operator
Question 1 |
The operation which is commutative but not associative is:
AND | |
OR | |
EX-OR | |
NAND |
Question 1 Explanation:
NAND and NOR operation follow commutativity but do not follow associativity.
Question 2 |
All digital circuits can be realized using only
Ex-OR gates | |
Multiplexers | |
Half adders | |
OR gates | |
Both B and C |
Question 2 Explanation:
NOR gate, NAND gate, Multiplexers and Half adders can also be used to realize all digital circuits.
Question 3 |
Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below.
The value of the expression 3+1+5∗2 / 7+2−4−7−6 / 2 as per the above rules is __________
Operator | Precedence | Associativity |
+ | Highest | Left |
− | High | Right |
∗ | Medium | Right |
/ | Low | Right |
6 | |
Question 3 Explanation:
3+1+5∗2 / 7+2−4−7−6 / 2
⇒ [ 3+1] +5∗2 / 7+2−4−7−6 / 2 [ + is highest precedence and its associativity is left ]
=> [4+5]∗2 / 7+2−4−7−6 / 2 [ + is highest precedence and its associativity is left ]
=> 9*2 / [7+2]−4−7−6 / 2 [ + is highest precedence and its associativity is left ]
=> 9*2 / 9 −4−7−6 / 2
=> 9*2 / 9 −4−[7−6] / 2 [ - is high precedence and its associativity is Right ]
=> 9*2 / 9 −[4−1] / 2 [ - is high precedence and its associativity is Right ]
=> 9*2 / [9 −3] / 2 [ - is high precedence and its associativity is Right ]
=> 9*2 / 6 / 2 [ * is next precedence and its associativity is Right ]
=> 18/6/2
=>18/[6/2] [ only / operator and its associativity is Right ]
=> 18 / 3
=> 6
Question 4 |
Which of the following operators can be used if a portion of a given bit patterns needs to be copied to a new word, while the remainder of the new word is filled with 0’s?
Logical AND | |
Bitwise AND | |
Bitwise OR | |
Bitwise XOR |
Question 4 Explanation:
Bitwise AND is a binary operator that operates on two equal-length bit patterns. If both bits in the compared position of the bit patterns are 1, the bit in the resulting bit pattern is 1, otherwise 0.
Bitwise OR is also a binary operator that operates on two equal-length bit patterns, similar to bitwise AND. If both bits in the compared position of the bit patterns are 0, the bit in the resulting bit pattern is 0, otherwise 1.
Bitwise XOR also takes two equal-length bit patterns. If both bits in the compared position of the bit patterns are 0 or 1, the bit in the resulting bit pattern is 0, otherwise 1.
Bitwise OR is also a binary operator that operates on two equal-length bit patterns, similar to bitwise AND. If both bits in the compared position of the bit patterns are 0, the bit in the resulting bit pattern is 0, otherwise 1.
Bitwise XOR also takes two equal-length bit patterns. If both bits in the compared position of the bit patterns are 0 or 1, the bit in the resulting bit pattern is 0, otherwise 1.
Question 5 |
Which of the following ‘C’ language arithmetic expressions has logical error?
-13 % -5 + 3; | |
4 / (-10 % -2) / 3; | |
3 / (-13 % -5) / 3; | |
-5 % 3 / 13; |
Question 5 Explanation:
→In the option B, -10%-2 gives remainder of “0” and then expression becomes 4/0/3.
→4/0 gives divide by zero error.
→4/0 gives divide by zero error.
Question 6 |
In C language, x - = y + 1; means
x=x-y+1 | |
x=-x-y-1 | |
x=-x+y+1 | |
x=x-y-1 |
Question 6 Explanation:
In general, a-=b means a=a-b. So from this we can conclude that correct option is A.
Question 7 |
main( ) { int x; x=3*4%5; printf(“x=%d”,x); }
The output is
x=2 | |
x=2.3
| |
x=5 | |
x=1.9
|
Question 7 Explanation:
‘*’ and ‘%’ operator have the same precedence but the associativity is from left to write. So x = 3*4%5 = 12%5 = 2.
Question 8 |
In C++ operator, << operator is called as
an insertion operator or put to operator | |
an extraction operator or get from operator
| |
an insertion operator or get from operator | |
None of the given options |
Question 8 Explanation:
In C++ operator, << operator is called as an an insertion operator or put to operator.
Question 9 |
If x=5, y=2, then x^y equals (where, ^ is a bitwise XOR operator)
00000111 | |
10000010
| |
10100000 | |
11001000 |
Question 9 Explanation:
In XOR,
1 XOR 1 = 0
1 XOR 0 =1
0 XOR 0 = 0
0 XOR 1 = 1
So 5 in binary form is 00000101 and 2 in binary form is 00000010.
Hence 00000101 XOR 00000010 = 00000111.
1 XOR 1 = 0
1 XOR 0 =1
0 XOR 0 = 0
0 XOR 1 = 1
So 5 in binary form is 00000101 and 2 in binary form is 00000010.
Hence 00000101 XOR 00000010 = 00000111.
Question 10 |
What is the output of the following C program
#include int main() { int i=5; printf("%d%d%d", i++, i ,++i); return 0; }
7 6 6
| |
6 7 8 | |
6 7 7 | |
5 6 7
|
Question 10 Explanation:
int i=5;
printf("%d%d%d", i++, i ,++i);
In printf() the firstly the calculation is done from right to left and then printing is done from left to right.
So first ++i will increase the value of i by 1 and make it 6. Now the i will be read simply for second calculation.And now i++ will be calculated which will increment the value of i by 1 and make it 7, but since it is post increment so first 6 will be printed and then increment will be done and then for rest two 7 and 7 will be printed .Hence the output will be 6,7,7.
printf("%d%d%d", i++, i ,++i);
In printf() the firstly the calculation is done from right to left and then printing is done from left to right.
So first ++i will increase the value of i by 1 and make it 6. Now the i will be read simply for second calculation.And now i++ will be calculated which will increment the value of i by 1 and make it 7, but since it is post increment so first 6 will be printed and then increment will be done and then for rest two 7 and 7 will be printed .Hence the output will be 6,7,7.
Question 11 |
Consider the following conditional code, which returns a Boolean values
if ((x>25) && (y>100))
return 'false';
else if((x<=25) && (y<=100)
return 'true';
else if((x>25) && (y<=100)
return 'false';
else
return 'true';
simplify it by filling in the following blank with a single Boolean expression without changing the behaviour of the conditional code.
if( ...........)
return 'true';
else
return 'false';
if ((x>25) && (y>100))
return 'false';
else if((x<=25) && (y<=100)
return 'true';
else if((x>25) && (y<=100)
return 'false';
else
return 'true';
simplify it by filling in the following blank with a single Boolean expression without changing the behaviour of the conditional code.
if( ...........)
return 'true';
else
return 'false';
x>25 | |
x<=25 | |
y>100 | |
y<=100 |
Question 11 Explanation:
According to given conditions, if x value is < = 25 means it will return true and for other values it will return false.
Alone y<=100 won't return true, it should be along with x<=25
Alone y<=100 won't return true, it should be along with x<=25
Question 12 |
Of the following, which is NOT a logical error?
Using the '=', instead of '==' to determine if two values are equal | |
Divide by zero | |
Failing to initialize counter and total variables before the body of loop. | |
Using commas instead of two required semicolon in a for loop header |