C Variables and Datatypes-2
1. Types of Integers are ______
a) short
b) int
c) long
d) All the above
Answer: D
short, int and long all are used to store integer datatypes.
2. What is the output of this program?
#include <stdio.h>
int main() {
printf("%x",-1<<4);
return 0;
}
a) fff0
b) fff1
c) fff2
d) fff3
Answer: A
-1 will be represented in binary form as: 1111 1111 1111 1111 Now -1<<4 means 1 is Shifted towards left by 4 positions, hence it becomes: 1111 1111 1111 0000 in hexadecimal form - fff0.
3. The format identifier ‘%i’ is also used for _____ datatype?
a) char
b) int
c) float
d) double
Answer: B
%i and %d both format specifiers are used for int datatype.
4. Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) short
b) int
c) long
d) double
Answer: A
65000 comes in the range of short (16-bit) which occupies the least memory.
5. Which of the following is a User-defined data type?
a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age};
d) All of the mentioned
Answer: D
typedef and struct are used to define user-defined data types.
6. Range of signed char and unsigned char are?
a) -128 to +127, 0 to 255
b) 0 to 255, -128 to +127
c) -128 to -1, 0 to +127
d) 0 to +127, -128 to -1
Answer: A
Advantage of an unsigned representation is only to increase the upper limit i.e positive limit. Size of a char remains same i.e 1 Byte.
7. Size of float, double and long double in Bytes are?
a) 4, 8, 16
b) 4, 8, 10
c) 2, 4, 6
d) 4, 6, 8
Answer: B
The size of float, double and long double are 4 bytes, 8 bytes and 10 bytes respectively.
8. Range of float variable is?
a) -3.8e32 to +3.8e32
b) -3.4e34 to +3.4e34
c) -3.4e38 to +3.4e38
d) -3.2e38 to +3.2e38
Answer: C
The size of the float datatype is already defined in C compilers which is -3.4e38 to +3.4e38.
9. Left most bit 0 in Singed representation indicates?
a) A Positive number
b) A Negative Number
c) An Unsigned number
d) None of the above
Answer: A
0 is used as the left most bit for positive numbers and 1 is used as a left most bit for negative numbers.
10. If you do not specify a storage class for a Variable?
a) You get compiler error
b) You get a compiler warning
c) Output is null always
d) None of the above
Answer: D
Yes, Even if you do not specify a Storage class for a Variable AUTOMATIC storage class is applied.