C Programming Multiple Choice Questions On Data Types

This page contains multiple choice questions on data types in c.

Practice Your Knowledge with MCQ on Data Types in C

1. What is short int in C programming?
a) Short is the qualifier and int is the basic data type
b) Qualifier
c) Basic data type of C
d) None of the above


Answer:a
Explanation: The size of the short int type is 2 bytes (16 bits) and, accordingly, it allows expressing the range of values equal to 2 to the power 16: 2^16 = 65 536.Since the short type is a signed one, and contains both positive and negative values, the range of values is between -32 768 and 32 767.

2. What is the output of this code?
#include <stdio.h>

int main()
{

   signed char chr;

   chr = 128;

   printf("%d\n", chr);

   return 0;
}
a)128
b)Depends on compiler
c)-128
d)None of mentioned


Answer:c
Explanation: signed char will be a negative number

3. Which data type is used to store a single character?
a) int
b) char
c) double
d) char[]


Answer:b

4. Which data type is used to store integer?
a) int
b) float
c) char
d) double


Answer:a

5. Which of the following is not a valid declaration in C?
1. short int x;

2. signed short x;

3. short x;

4. unsigned short x;
a)2 and 4
b)3
c)1
d)All are valid


Answer:d
Explanation: C supports all above declarations

6. Which data type is used to store floating point numbers?
a) char
b) int
c) double
d) float
e) Both c and d


Answer:e
Explanation: Both float and double are used to store floating point numbers but double gives extra precision.

7. What is the size of int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined


Answer:c
Explanation: The size of the data types depend on the system.

8. Which data type is considered as empty or nothing in C programming language?
a) void
b) nothing
c) enum
d) char


Answer:a
Explanation: void is considered empty data type in C programming language.

9. Which operator gives size of specified data type or variable in bytes?
a) size()
b) sizeof()
c) getSize()
d) sizeOf()


Answer:b
Explanation: sizeof() operator gives the size of specified data type or variable in bytes.

10. What is the output of following C programming code?
#include <stdio.h>
int main()
{
   float c = 5.0;
   printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32);
   return 0;
}
a)Temperature in Fahrenheit is 41.00
b)Temperature in Fahrenheit is 37.00
c)Temperature in Fahrenheit is 0.00
d)Compiler Error


Answer:b
Explanation: Since 9 and 5 are integers, integer arithmetic happens in subexpression (9/5) and we get 1 as its value. To fix the above program, we can use 9.0 instead of 9 or 5.0 instead of 5 so that floating point arithmetic happens. 1

11. What is the size of char data type?
a) 1 byte
b) 2 bytes
c) 3 bytes
d 4 bytes


Answer:a
Explanation: Size of chardata type in C programming language is 1 byte.

12. The format identifier ‘%i’ is also used for _____ data type?
a) char
b) int
c) float
d) double


Answer:b
Explanation: Both %d and %i can be used as a format identifier for int data type.

12. What is the size of int data type in 16 bit machine?
a) 4 bytes
b) 5 bytes
c) 16 bytes
d) 2 bytes


Answer:d
Explanation: Size of int data type in C programming language for 16 bit machine is 2 bytes.

14. 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:b
Explanation: typedef and struct are used to define user-defined data types.

15. What is the size of int data type in 32 bit machine?
a) 4 bytes
b) 3 bytes
c) 2 bytes
d) 1 byte


Answer:a
Explanation: Size of int data type in C programming language for 32 bit machine is 4 bytes.

16. Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short
b) unsigned short
c) long
d) int


Answer:b
Explanation: 65000 comes in the range of short (16-bit) which occupies the least memory. Signed short ranges from -32768 to 32767 and hence we should use unsigned short.

17. Which of the following is structured data type?
a) int
b) array
c) char
d) double


Answer:b
Explanation: array is a structured data type in C programming language.

18. What is the output of this code?
#include <stdio.h>
int main()
{
    char a = '\012';
 
    printf("%d", a);
 
    return 0;
}
a)Compiler Error
b)12
c)10
d)Empty


Answer:c
Explanation: The value '\012' means the character with value 12 in octal, which is decimal 10

19. What is the output of this code?

#include<stdio.h>
int main()
{
    char c = 125;
    c = c+10;
    printf("%d", c);
    return 0;
}
a)135
b)+INF
c)-121
d)-8


Answer:c

19. The memory space taken by long int data type?
a) 16
b) 8
c) 2
d) 4


Answer:b
Explanation: The size of the long type is 8 bytes (64 bits). The minimum value is -9 223 372 036 854 775 808, the maximum value is 9 223 372 036 854 775 807.

20. The space taken by unsinged char data type? a) 1
b) 2
c) 3
d) 4


Answer:a
Explanation: The uchar integer type also occupies 1 byte of memory, as well as the char type, but unlike it uchar is intended only for positive values. The minimum value is zero, the maximum value is 255. The first letter u in the name of the uchar type is the abbreviation for unsigned.

20. The space taken by float data type? a) 1
b) 2
c) 3
d) 4


Answer:d

20. The space taken by long double data type? a) 2
b) 4
c) 8
d) 10


Answer:d

20. Which keyword is used to create new data type names (also for existing types) in C programming language?
a) enum
b) type
c) typedef
d) new type


Answer:c
Explanation: typedef keyword is used to create new data type names.

21. Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3. If n is large, which of the following statements is most likely to set p correctly?
a)p = n * (n-1) * (n-2) / 6;
b)p = n * (n-1) / 2 * (n-2) / 3;
c)p = n * (n-1) / 3 * (n-2) / 2;
d)p = n * (n-1) * (n-2) / 6.0;


Answer:b
Explanation: As n is large, the product n*(n-1)*(n-2) will go out of the range(overflow) and it will return a value different from what is expected. Therefore, option (A) and (D) are eliminated. So we consider a shorter product n*(n-1). n*(n-1) is always an even number. So the subexpression " n * (n-1) / 2 " in option B would always produce an integer, which means no precision loss in this subexpression. And when we consider " n*(n-1)/2*(n-2) ", it will always give a number which is a multiple of 3. So dividing it with 3 don't have any loss.

22. What is the output of the following C code?
#include<stdio.h>
int main(){
    printf("%d \t",sizeof(7.5));
    printf("%d",sizeof('A'));
    return 0;
}
a) 8 2
b) 4 2
c) 4 4
d) 2 8


Answer:a

23. The format identifier ‘%i’ is also used for _____ data type.
a) int
b) char
c) double
d) float


Answer:a
Explanation: Both %d and %i can be used as format identifier for int data type.

24. Which of the following is not modifier of data type in c? a) extern
b) huge
c) interrupt
d) register
e) All of above


Answer:e

25. What will be the output of the following C code?

#include<stdio.h>
int main()
{
    float f1 = 0.1;
    
    if (f1 == 0.1)
       printf("Equal");
    else
       printf("Not Equal");
}
a) Not Equal
b) Equal
c) Depends on the compiler
d) error


Answer:b
Explanation: The value 0.1 by default is of type double so it had different representation than float which results in inequality even after conversion.

26. Which of the following is valid data type?
a) integer
b) floating
c) int
d) precision


Answer:c

27. Which of the following is user defined data type?
a) typedef enum {Sun, Mon, Tue, Wed, Thu, Fri, Sat} Days_Of_Week;
b) typedef int integer;
c) struct {char full_name[10], int age}
d) All of above


Answer:d

28. Which of the following data type is incorrect?
a) character
b) int
c) float
d) double


Answer:a

29. How much memory space is taken by long int data type in C?
(Consider 32 bit system) a) 2
b) 4
c) 8
d) 16


Answer:c
Explanation: Storage space for int data type is 4 bytes in case of 32 bit processor. We can increase the range by using long int which is 8 bytes.

30. Which of the following data type has more precision in C?
a) int
b) float
c) double
d) long double


Answer:d