Operator

Question 1
Which of the following ‘C’ language arithmetic expressions has logical error?
A
-13 % -5 + 3;
B
4 / (-10 % -2) / 3;
C
3 / (-13 % -5) / 3;
D
-5 % 3 / 13;
Question 1 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.
Question 2
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?
A
Logical AND
B
Bitwise AND
C
Bitwise OR
D
Bitwise XOR
Question 2 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.
Question 3
In C language, x - = y + 1; means
A
x=x-y+1
B
x=-x-y-1
C
x=-x+y+1
D
x=x-y-1
Question 3 Explanation: 
In general, a-=b means a=a-b. So from this we can conclude that correct option is A.
Question 4
main( )
{
   int x;
   x=3*4%5;
   printf(“x=%d”,x);
} 

The output is

A
x=2
B
x=2.3
C
x=5
D
x=1.9
Question 4 Explanation: 
‘*’ and ‘%’ operator have the same precedence but the associativity is from left to write. So x = 3*4%5 = 12%5 = 2.
Question 5

What is the output of the following C program

#include
int main()
{
int i=5;
printf("%d%d%d", i++, i ,++i);
return 0;
} 
A
7 6 6
B
6 7 8
C
6 7 7
D
5 6 7
Question 5 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.
Question 6
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';
A
x>25
B
x<=25
C
y>100
D
y<=100
Question 6 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
Question 7
The condition num!=65 cannot be replaced by
A
num > 65 || num<65
B
!(num==65)
C
num-65
D
!(num-65)
Question 7 Explanation: 
Except !(num-65) can be replaced by num!=65
Question 8
Of the following, which is NOT a logical error?
A
Using the '=', instead of '==' to determine if two values are equal
B
Divide by zero
C
Failing to initialize counter and total variables before the body of loop.
D
Using commas instead of two required semicolon in a for loop header
Question 9
Given i= 0, j = 1, k = –1, x = 0.5, y = 0.0 What is the output of given ‘C’ expression ?
x * 3 && 3 || j | k
A
-1
B
0
C
1
D
2
Question 9 Explanation: 
Step-1: Evaluate x ​ * 3 because multiplication has more priority than remaining operators x * 3→ 1.5
Step-2: && is logical AND. Both the statements are TRUE, then it returns 1 otherwise 0.
1.5 && 3 is TRUE. So, it returns 1.
Step-3: j | k is bitwise OR operator. It returns -1.
Step-4: ((x * 3) && 3) || (j | k) islogical OR operator. It returns 1
Note: The precedence is ((x * 3) && 3) || (j | k)
Question 10
Find the output of the following “C” code :
main ( )
{
int x=20, y=35;
x= y++ + x++;
y= ++y + ++x;
printf (“%d, %d\n”, x,y);
}
A
55, 93
B
53, 97
C
56, 95
D
57, 94
E
56, 93
Question 10 Explanation: 
Step-1: Here, we are using post increment for both x and y. In post increment the value assign first and update after assigning.
x= 35 + 20
y= 37 + 56 (In this statement, ‘y’ will become 36 before performing pre increment)
Step-2: Final x=56 and y=93
Note: They given wrong options. We are added correct option.
Excluded for evaluation.
Question 11
main( )
{
char *str = “abcde”;
printf (“%c”, *str);
printf (“%c”, *str++);
printf (“%c”, *(str++));
printf (“%s”, str);
}
The output of the above ‘C’ code will be :
A
a a c b c d e
B
a a c c c d e
C
a a b c d e
D
None of these
Question 11 Explanation: 
The above program we are using post increment operators. In post increment the value assign first and update after assigning.
main( )
{
char *str = “abcde”;
printf (“%c”, *str); /* It returns character ‘a’ */
printf (“%c”, *str++); /* It returns character ‘a’ because it is used post increment*/
printf (“%c”, *(str++)); /* It returns character ‘b’ because the previous increment is update here and present also they given post increment, so it only returns ‘b’ */
printf (“%s”, str); /* It returns aabcde */
}
There are 11 questions to complete.

Access quiz wise question and answers by becoming as a solutions adda PRO SUBSCRIBER with Ad-Free content

Register Now

If you have registered and made your payment please contact solutionsadda.in@gmail.com to get access