Chapter 2 of C Programming introduces the essential concepts of data types and variables. This chapter covers the various data types in C, such as int, char, float, and double, which are used to store different kinds of information in a program. Understanding data types helps define the kind of data a variable can hold, ensuring proper memory allocation and data handling. Additionally, it explains how to declare and initialize variables, enabling programmers to store values effectively. This foundational knowledge of C variables and data types is crucial for building reliable and efficient C programs.
The best way to go through this MCQs collection is below:
Take a sheet
note down the answer options
Finally compare with the answers at last and score yourself.
Chapter 2: Data Types and Variables
Data Types (int, char, float, double, etc.)
Which data type is used to store whole numbers in C?
a) float
b) double
c) int
d) char
What is the size of the int data type in most 32-bit compilers?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 1 byte
Which data type is used to store a single character?
a) char
b) float
c) double
d) int
What is the typical size of a float data type?
a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 1 byte
Which data type would you use to store a large floating-point number with high precision?
a) int
b) char
c) double
d) float
Which of the following is a floating-point data type?
a) int
b) char
c) double
d) long
What is the value range of the char data type?
a) 0 to 127
b) -128 to 127
c) 0 to 255
d) -255 to 255
What keyword is used to define a constant floating-point number?
a) const float
b) float const
c) double
d) const double
Which data type would be the best choice for storing a person’s age?
a) int
b) float
c) double
d) char
The size of which data type is dependent on the system architecture?
a) int
b) char
c) double
d) float
Variable Declaration and Initialization
Which of the following is the correct way to declare an integer variable?
a) integer num;
b) int num;
c) num int;
d) var int num;
What is the correct syntax to initialize a variable x with a value of 5?
a) x = 5;
b) int x = 5;
c) x := 5;
d) int := 5;
Which of the following declares and initializes a variable in one line?
a) int x;
b) int x = 0;
c) x = 0;
d) initialize int x;
If a variable is declared without initialization, its value is:
a) Zero
b) Garbage value
c) Default value
d) -1
What is the initial value of an uninitialized float variable in C?
a) 0.0
b) Undefined
c) -1
d) Infinity
Which symbol is used for assignment in C programming?
a) =
b) ==
c) :=
d) =:
What is a variable in C?
a) A reserved word
b) A memory location
c) A constant value
d) A control structure
Which of the following is not a valid variable name in C?
a) total_sum
b) 2total
c) totalSum
d) TotalSum
Which keyword is used to declare a variable in C?
a) let
b) var
c) int
d) decl
What is the correct way to update the value of an integer variable num to 10?
a) num = 10;
b) update num to 10;
c) set num = 10;
d) var num = 10;
Constants and Literals
Which of the following declares a constant integer variable?
a) const int x = 5;
b) int const x = 5;
c) #define x 5
d) All of the above
What keyword is used to create a constant variable in C?
a) constant
b) const
c) define
d) static
Which of the following is a string literal?
a) ‘A’
b) “Hello”
c) 5
d) const
What is a literal in C?
a) A variable name
b) A constant value
c) A data type
d) A function
Which keyword is used for symbolic constants?
a) #const
b) #define
c) const
d) static
Which of the following statements is correct for constants in C?
a) They can be modified at any time
b) Their values cannot be changed
c) They can be used only within functions
d) They are stored in the stack
Which of the following is a valid integer literal?
a) “100”
b) 100
c) 100.0
d) 1e2
What is the value of the literal 'A' in integer form?
a) 0
b) 65
c) ‘A’
d) Undefined
How do you define a constant literal in C using the #define directive?
a) #define PI 3.14
b) #const PI 3.14
c) const PI = 3.14;
d) define PI = 3.14;
What does const float PI = 3.14; do in C?
a) Declares a constant float variable
b) Declares a regular variable
c) Declares a variable that can be changed
d) Declares an integer constant
Keywords and Identifiers
Which of the following is a keyword in C?
a) return
b) main
c) printf
d) int
Which of the following is a valid identifier in C?
a) for
b) 2total
c) _value
d) class
Keywords in C are:
a) User-defined words
b) Predefined reserved words
c) Synonyms for variables
d) Functions
Which of the following is not a valid keyword in C?
a) auto
b) case
c) execute
d) volatile
How many keywords are there in standard C?
a) 32
b) 28
c) 24
d) 30
Identifiers are:
a) User-defined names
b) Reserved words
c) Only used for constants
d) Defined only for functions
Which of the following is not an identifier?
a) variable1
b) #define
c) function_name
d) totalSum
Which identifier is valid in C?
a) total@sum
b) _total_sum
c) 5value
d) int
Which of these cannot be an identifier?
a) MyVariable
b) _temp
c) 123abc
d) var
What does the keyword void mean?
a) No return type
b) Empty variable
c) Reserved variable
d) Zero integer
Type Conversion (Implicit and Explicit)
What is implicit type conversion?
a) Automatic conversion of one data type to another
b) Manually converting one data type to another
c) Defining a new data type
d) All of the above
Which function is used for explicit type conversion?
a) atoi()
b) typecast
c) cast
d) convert
Which type conversion is handled by the compiler?
a) Explicit
b) Manual
c) Implicit
d) String
What is explicit type conversion also known as?
a) Typecasting
b) Implicit conversion
c) Auto conversion
d) Dynamic typing
What will the following code return? int a = (int) 3.14;
a) 3
b) 3.14
c) 4
d) 0
Which of the following best describes type conversion?
a) It allows functions to use any data type
b) Changing one data type to another
c) A part of syntax error
d) A technique to declare constants
Which of the following is an example of implicit type conversion?
a) int a = 5.0;
b) int a = (int)5.0;
c) double a = 3;
d) (float)a;
What is the term for converting a higher data type to a lower one?
a) Narrowing conversion
b) Widening conversion
c) Implicit conversion
d) Non-conversion
In C, which conversion will not happen automatically?
a) int to float
b) float to int
c) double to float
d) char to int
What is the result of float f = (float)10 / 3; in C?