Computer

Data Types, Variables & Constants MCQs with Answers

Which of the following is a primitive data type in C?
a) String
b) Float
c) Array
d) Class

Answer
b) Float

What is the default value of an uninitialized static integer in C?
a) 0
b) Null
c) Undefined
d) 1

Answer
a) 0

Which of the following data types can store the largest integer value?
a) int
b) long
c) float
d) double

Answer
b) long

What type of variable is used to store a single character in C?
a) char
b) string
c) int
d) float

Answer
a) char

Which of the following is NOT a valid variable name in C?
a) int_var
b) _var123
c) 123var
d) varName

Answer
c) 123var

What is the size of a float variable in C?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 16 bytes

Answer
b) 4 bytes

Which of the following constants is used to define a constant value in C?
a) const
b) define
c) #define
d) static

Answer
c) #define

What is the correct syntax for declaring a constant integer in C?
a) int const x = 10;
b) const int x = 10;
c) define int x = 10;
d) int x = 10; const

Answer
b) const int x = 10;

Which of the following is the size of the double data type in C?
a) 4 bytes
b) 8 bytes
c) 16 bytes
d) 2 bytes

Answer
b) 8 bytes

Which keyword is used to define a constant in C?
a) define
b) const
c) constant
d) static

Answer
b) const

What is the output of the following C code?
int x = 5; printf(“%d”, x);
a) 0
b) 5
c) x
d) Undefined

Answer
b) 5

Which of the following data types is used to store decimal values?
a) int
b) float
c) char
d) bool

Answer
b) float

Which of the following is the correct way to initialize a constant in C?
a) const int x = 10;
b) int const x = 10;
c) int x = 10; const
d) Both a and b

Answer
d) Both a and b

Which of the following is a valid constant declaration in C?
a) const int x = 10;
b) int x = 10; const
c) #define x 10
d) x = 10; const

Answer
a) const int x = 10;

What is the size of the char data type in C?
a) 1 byte
b) 2 bytes
c) 4 bytes
d) 8 bytes

Answer
a) 1 byte

Which data type can be used to store a boolean value in C?
a) int
b) char
c) bool
d) There is no boolean data type in C

Answer
d) There is no boolean data type in C

Which of the following is the correct format specifier for a float variable in C?
a) %d
b) %f
c) %c
d) %s

Answer
b) %f

What will be the output of the following C code?
int x = 10, y = 20; printf(“%d”, x + y);
a) 10
b) 20
c) 30
d) Undefined

Answer
c) 30

Which of the following keywords is used to declare a variable in C that cannot be modified?
a) static
b) const
c) mutable
d) final

Answer
b) const

What is the range of values that can be stored in an unsigned int?
a) -2147483648 to 2147483647
b) 0 to 4294967295
c) -2147483648 to 0
d) 0 to 32767

Answer
b) 0 to 4294967295

What type of value does a char data type hold?
a) Boolean value
b) Integer value
c) Character value
d) Decimal value

Answer
c) Character value

Which of the following is a valid declaration of a pointer in C?
a) int *p;
b) pointer p;
c) int p*;
d) int* p;

Answer
d) int* p;

Which of the following statements is true about the const keyword in C?
a) const can be used to declare both constants and variables
b) const variables cannot be modified
c) The const keyword can only be used with integer data types
d) const variables must be declared as global variables

Answer
b) const variables cannot be modified

What is the default value of a global static variable in C?
a) Null
b) 0
c) Undefined
d) 1

Answer
b) 0

Which of the following is used to define a constant value in C?
a) #define
b) define
c) const
d) All of the above

Answer
d) All of the above

Which data type is used to represent a very large integer in C?
a) int
b) long
c) long long
d) double

Answer
c) long long

Which of the following will store the number 3.14 in a variable of type float?
a) float pi = 3.14;
b) float pi = 3.14f;
c) double pi = 3.14;
d) float pi = 3.14d;

Answer
b) float pi = 3.14f;

What is the valid range of a signed char variable in C?
a) -128 to 127
b) 0 to 255
c) -32768 to 32767
d) 0 to 32767

Answer
a) -128 to 127

Which of the following is an example of a constant in C?
a) const int x = 10;
b) #define x 10
c) x = 10;
d) Both a and b

Answer
d) Both a and b

Which data type is used to represent true or false values in C?
a) bool
b) char
c) int
d) There is no true/false data type in C

Answer
d) There is no true/false data type in C

What is the purpose of the sizeof operator in C?
a) To calculate the size of a variable
b) To get the size of the memory
c) To return the size of a data type
d) To calculate the size of a constant

Answer
c) To return the size of a data type

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button