C Fundamentals - Study Mode
[#136] What will be the output of the following C code? #include <stdio.h>
int main()
{
unsigned int i = 23
signed char c = -23
if (i > c)
printf("Yes
")
else if (i < c)
printf("No
")
}
Correct Answer
(B) No
[#137] What will be the output of the following C code? #include <stdio.h>
int main()
{
int x = 2
x = x << 1
printf("%d
", x)
}
Correct Answer
(A) 4
[#138] If integer needs two bytes of storage, then maximum value of an unsigned integer is
Correct Answer
(A) 2 16 – 1
Explanation
Solution: An integer is a number with no fractional part
it can be positive, negative or zero. In ordinary usage, one uses a minus sign to designate a negative integer. However, a computer can only store information in bits, which can only have the values zero or one. We might expect, therefore, that the storage of negative integers in a computer might require some special technique. As you might imagine, an unsigned integer is either positive or zero.
Consider a single digit decimal number: In a single decimal digit, you can write a number between 0 and 9. In two decimal digits, you can write a number between 0 and 99, and so on.
Since nine is equivalent to 10 1 - 1,
99 is equivalent to 10 2 - 1, etc.
In n decimal digits, you can write a number between 0 and 10 n - 1.
So, analogously, in the binary number system,
An unsigned integer containing n bits can have a value between 0 and 2 n - 1
(which is 2 n different values).
[#139] What number would be shown on the screen after the following statements of C are executed? char ch
int i
ch = 'G'
i = ch-'A'
printf("%d", i)
Correct Answer
(B) 6
Explanation
Solution: Since the ASCII value of G is 71 and the garbage value if A is 65 and hence the difference is 6.
[#140] Find the output of the following program. void main () { int i=01289
printf ( " %d ", i )
}
Correct Answer
0289
Explanation
Solution: The prefix 0 in an integer value indicates octal value. In octal value use of 8 and 9 is not allowed and hence the error.