Q1. Which of the following is a primitive data type in most languages?
- A.List
- B.Integer✓ Correct
- C.Object
- D.Array
Explanation
Integer is a primitive (basic) data type available in virtually all programming languages.
Topic in Programming
A data type defines the set of values a variable can hold and the operations allowed on them, while a variable is a named storage location for such a value. MCQs check primitive types such as int, float, double, char and boolean, their sizes, and what happens on integer overflow or integer division. Conversions are a favourite area: implicit widening, explicit casting and lossy narrowing conversions. Expect variable scope and lifetime, constants, and the contrast between static, dynamic and duck typing. More advanced questions cover type erasure in Java generics, type inference, tagged or discriminated unions, and the idea of type-level programming.
Below are 30 practice questions from a pool of 210 Data Types & Variables MCQs, one of 16 topics in Programming. Each shows the correct answer with an explanation; when you are ready, take a timed quiz to test recall under exam conditions.
Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Q1. Which of the following is a primitive data type in most languages?
Integer is a primitive (basic) data type available in virtually all programming languages.
Q2. What data type is used to store true or false values?
The boolean data type stores only two values: true or false.
Q3. What is a variable?
A variable is a named location in memory that holds a value which can change during program execution.
Q4. What is the default value of an integer variable in Java?
In Java, the default value for an int instance variable is 0.
Q5. Which data type would you use to store a single letter?
The char data type is designed to store a single character.
Q6. What is the difference between float and double?
double uses 64 bits and provides more precision than float which uses 32 bits.
Q7. What does declaring a variable mean?
Declaring a variable means telling the compiler its name and data type so memory can be allocated.
Q8. Which keyword is used to declare a constant in Java?
In Java, the 'final' keyword is used to declare a constant whose value cannot be changed after initialization.
Q9. What is a string?
A string is a sequence of characters used to represent text.
Q10. What is type casting?
Type casting is the process of converting a value from one data type to another, such as int to float.
Q11. What is the difference between implicit and explicit type casting?
Implicit casting (widening) is automatic and safe; explicit casting (narrowing) requires manual intervention and may lose data.
Q12. What is the size of an int in Java?
In Java, an int is always 32 bits (4 bytes) regardless of the platform.
Q13. What is the difference between value types and reference types?
Value types hold data directly in memory, while reference types store a reference (address) to the data's location.
Q14. What happens when you assign a float value to an int variable without casting?
In strongly typed languages like Java, assigning a float to an int without explicit casting causes a compilation error.
Q15. What is an enumeration (enum)?
An enum defines a fixed set of named constants, improving code readability and type safety.
Q16. What is the difference between signed and unsigned integers?
Signed integers can represent both negative and positive values, while unsigned integers represent only non-negative values.
Q17. What is a nullable type?
A nullable type can hold either a valid value of its underlying type or null, indicating the absence of a value.
Q18. What is the result of integer overflow?
In most languages, integer overflow causes the value to wrap around due to fixed bit representation.
Q19. What is a union type in TypeScript?
A union type (e.g., string | number) allows a variable to hold a value of any of the specified types.
Q20. What is type aliasing?
Type aliasing creates an alternative name for an existing type, improving readability (e.g., typedef in C, type in TypeScript).
Q21. What is the IEEE 754 standard?
IEEE 754 defines the representation and behavior of floating-point numbers in computing, including special values like NaN and Infinity.
Q22. What is a phantom type?
Phantom types are type parameters that don't correspond to any runtime data but enforce constraints at compile time.
Q23. What is the difference between structural typing and nominal typing?
Structural typing (e.g., TypeScript) considers types compatible if their structures match; nominal typing (e.g., Java) requires explicit declarations.
Q24. What is type erasure in Java generics?
Type erasure removes generic type information at runtime, replacing it with raw types and inserting casts as needed for backward compatibility.
Q25. What is a dependent type?
A dependent type is a type whose definition depends on a value, allowing more precise type specifications (e.g., a vector of length n).
Q26. What is the bottom type in type theory?
The bottom type (e.g., Never in Kotlin, never in TypeScript) has no values and is a subtype of all types, often used for functions that never return.
Q27. What is variance in type systems?
Variance describes how subtyping of container/generic types relates to the subtyping of their type parameters (covariant, contravariant, invariant).
Q28. What is an algebraic data type (ADT)?
ADTs are composite types formed via sum types (tagged unions/enums) and product types (tuples/records), common in functional languages.
Q29. What is the unit type?
The unit type has exactly one value (e.g., () in Rust/Haskell, Unit in Kotlin) and represents the absence of meaningful data, similar to void.
Q30. What is the purpose of type witnesses in advanced type systems?
Type witnesses are explicit terms that prove type equalities or relationships, helping the compiler verify complex type-level computations.
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Practice MCQs with explanations
Take a timed quiz drawn from 210+ questions on this topic. No signup required — your progress saves in your browser.
Start Data Types & Variables Quiz