C Operators and Expression-3
1. If i j,k are integer variable with values 1,2,3 respectively, then what is the value of the expression
a) 6
b) 5
c) 1
d) 0
Answer: C
No explanation is given for this question.
2. The expression a << 6 shifts all bits of a six places to the left. If a Ox6db7, then what is the value of a << 6
a) 0xa72b
b) 0xa2b
c) 0x6dc0
d) 0x1111
Answer: C
No explanation is given for this question.
3. Choose the correct statements
a) address operator cannot be applied to register variables
b) misuse of register declaration will increase the execution time
c) Both (a) & (b)
d) none of above
Answer: C
No explanation is given for this question.
4. Choose the correct statement for the given code:
int **a;
a) is illegal
b) is legal but meaningless
c) is syntactically and semantically correct
d) none of these
Answer: C
No explanation is given for this question.
5. Determine Output:
void main() {
int i = 0, j = 1, k = 2, m;
m = i++ || j++ || k++;
printf("%d %d %d %d", m, i, j, k);
}
a) 1 1 2 3
b) 1 1 2 2
c) 0 1 2 2
d) 0 1 2 3
e) None of these
Answer: B
In an expression involving || operator, evaluation takes place from left to right and will be stopped if one of its components evaluates to true(a non zero value).
So in the given expression m = i++ || j++ || k++.
It will be stop at j and assign the current value of j in m.
therefore m = 1 , i = 1, j = 2 and k = 2 (since k++ will not encounter. so its value remain 2).
6. Determine Output :
void main() {
int c = - -2;
printf("c = %d", c);
}
a) 1
b) -2
c) 2
d) Error
Answer: C
Here unary minus (or negation) operator is used twice. Same maths rules applies, ie. minus * minus = plus.
Note: However you cannot give like --2. Because -- operator can only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.
7. Determine Output:
void main() {
int i = 10;
i = !i>14;
printf("i = %d", i);
}
a) 10
b) 14
c) 0
d) None of these
Answer: C
In the expression !i>14 , NOT (!) operator has more precedence than ' >' symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).
8. What is the output of the following statements?
int b = 15, c = 5, d = 8, e = 8, a;
a = b>c ? 12 : d>e ? 13 : 14 :15;
printf("%d", a);
a) 13
b) 14
c) 15
d) 12
e) Garbage Value
Answer: B
No explanation is given for this question.
9. What is the use of size() operator?
a) To get the size of data types or variables in bytes
b) To get size of data types only
c) To get size of the variables only
d) All of the above
Answer: A
No expression is given for this question.
10. What is the use of typedef keyword?
a) To create user defined data type
b) To create special functions
c) To change the meaning of built in datatypes
d) None of the above
Answer: A
No explanation is given for this question.