C Multiple Choice Questions & Answers (MCQs) on “Signed Qualifier”.
1. In a signed integer, the sign is represented by ___________
a) Least significant bit
b) Most significant bit
c) System dependent
d) The mean of the most significant bit and the least significant bit
Answer: b
Clarification: In a signed integer, the most significant bit represents the sign whereas, in an unsigned integer, no bit is used to represent the sign.
2. Sign qualifiers can be applied to double.
a) True
b) False
Answer: b
Clarification: Sign qualifiers cannot be applied to the data types: float and double
3. What will be the output of the following C code?
#includeint main() { signed char ch= ‘a’; printf(“%u”,ch); return 0; }
a) -65
b) 65
c) -97
d) 97
Answer: d
Clarification: Only for completeness, sign qualifiers are available with char data type.
4. What will be the output of the following C code?
#includemain() { signed char a[]= “BAT”; printf(“%c”, a[1]); return 0; }
a) -A
b) BAT
c) A
d) 65
Answer: c
Clarification: Sign qualifiers are available for char data types only for completeness. Format specifier used: %c, which prints a character. a[1] will print ‘A’.
5. What is the default state of an integer in c language?
a) Signed
b) Unsigned
c) System dependent
d) There is no default state
Answer: a
Clarification: The default state of an integer in c language is signed. Hence we can store both positive and negative integer values in it.
6. Suppose we have: int a=100; (signed by default).
If we want to convert this to an unsigned long integer, we can do this by making the following small change:
a) int a=lu100;
b) int a= 100ul;
c) int a=uu100;
d) int a=100uu;
Answer: b
Clarification: An integer literal can have a suffix that is a combination of U and L( uppercase or lowercase). The prefix specifies the base or the radix, ie: 0x for hexadecimal, 0 for octal and nothing for decimal.
7. What is the binary representation of the integer -14?
a) 11110
b) 01110
c) 01100
d) 11100
Answer: a
Clarification: The left most bit (most significant bit) is used to represent the sign of the number: 0 for positive and 1 for negative. For example, a value of positive 14 is written as 01110(in binary). But a value of negative 14 is written as: 11110.
8. Which of the following header files must necessarily be included in your code, if you want to find the minimum value of unsigned short integer?
a) stdio.h
b) stdlib.h
c) limits.h
d) math.h
Answer: c
Clarification: The header file limits.h is used to find the value of constants such as minimum and maximum. stdio.h: standard input and output, stdlib.h: standard library, math.h: mathematics functions library
9. What will be the error in the following C code?
main() { long float a=-25.373e22; printf("%lf",a); }
a) Negative number cannot be assigned to float data type
b) Long and float cannot be used together
c) Does not result in error
d) Logical error
Answer: b
Clarification: It is not possible to use sign qualifier with float data type, however in the above code a negative value has been assigned to the variable without the use of sign qualifiers, which is possible. Hence, the answer is not “negative number cannot be assigned to float data type”. we know that size qualifier long is not applicable for float data type, hence the error.
10. What will be the output of the following C code?
main() { unsigned a=10; long unsigned b=5l; printf(“%lu%u”,a,b); }
a) 105
b) 510
c) 10
d) error
Answer: a
Clarification: The format specifiers which are for unsigned and long unsigned have been used in the code. Had we used the format specifiers in the reverse order, the output would still be the same.