HomeSubjectsUniversityBlogAbout

Data Types & Variables

Topic in Programming

210 total MCQsShowing 30 with explanations10 Easy10 Medium10 Hard

About This Topic

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.

Practice Questions

Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.

Data Types & VariablesEasy

Q1. Which of the following is a primitive data type in most languages?

  1. A.List
  2. B.Integer✓ Correct
  3. C.Object
  4. D.Array

Explanation

Integer is a primitive (basic) data type available in virtually all programming languages.

Report an error in this question

Data Types & VariablesEasy

Q2. What data type is used to store true or false values?

  1. A.string
  2. B.float✓ Correct
  3. C.boolean
  4. D.integer

Explanation

The boolean data type stores only two values: true or false.

Report an error in this question

Data Types & VariablesEasy

Q3. What is a variable?

  1. A.A fixed constant value in the program
  2. B.A reusable block of executable code
  3. C.A named storage location in memory✓ Correct
  4. D.A control structure for iteration

Explanation

A variable is a named location in memory that holds a value which can change during program execution.

Report an error in this question

Data Types & VariablesEasy

Q4. What is the default value of an integer variable in Java?

  1. A.1
  2. B.-1
  3. C.0✓ Correct
  4. D.null

Explanation

In Java, the default value for an int instance variable is 0.

Report an error in this question

Data Types & VariablesEasy

Q5. Which data type would you use to store a single letter?

  1. A.String
  2. B.double
  3. C.boolean
  4. D.char✓ Correct

Explanation

The char data type is designed to store a single character.

Report an error in this question

Data Types & VariablesEasy

Q6. What is the difference between float and double?

  1. A.They are exactly the same data type
  2. B.double has more precision than float✓ Correct
  3. C.double is used for storing integers
  4. D.float has more precision than double

Explanation

double uses 64 bits and provides more precision than float which uses 32 bits.

Report an error in this question

Data Types & VariablesEasy

Q7. What does declaring a variable mean?

  1. A.Specifying its name and type✓ Correct
  2. B.Assigning it an initial value
  3. C.Printing its current value
  4. D.Removing it from the memory

Explanation

Declaring a variable means telling the compiler its name and data type so memory can be allocated.

Report an error in this question

Data Types & VariablesEasy

Q8. Which keyword is used to declare a constant in Java?

  1. A.static
  2. B.fixed
  3. C.final✓ Correct
  4. D.const

Explanation

In Java, the 'final' keyword is used to declare a constant whose value cannot be changed after initialization.

Report an error in this question

Data Types & VariablesEasy

Q9. What is a string?

  1. A.A boolean value
  2. B.A single character
  3. C.A sequence of characters✓ Correct
  4. D.A numeric data type

Explanation

A string is a sequence of characters used to represent text.

Report an error in this question

Data Types & VariablesEasy

Q10. What is type casting?

  1. A.Removing a variable from program memory
  2. B.Declaring a variable with a specific name
  3. C.Converting a value from one type to another✓ Correct
  4. D.Defining a brand new composite data type

Explanation

Type casting is the process of converting a value from one data type to another, such as int to float.

Report an error in this question

Data Types & VariablesMedium

Q11. What is the difference between implicit and explicit type casting?

  1. A.Implicit casting always causes errors while explicit casting never does
  2. B.Implicit is done automatically by the compiler; explicit is done manually✓ Correct
  3. C.Explicit casting executes much faster than implicit casting at runtime
  4. D.They are exactly the same type conversion process with no differences

Explanation

Implicit casting (widening) is automatic and safe; explicit casting (narrowing) requires manual intervention and may lose data.

Report an error in this question

Data Types & VariablesMedium

Q12. What is the size of an int in Java?

  1. A.32 bits✓ Correct
  2. B.16 bits
  3. C.8 bits
  4. D.64 bits

Explanation

In Java, an int is always 32 bits (4 bytes) regardless of the platform.

Report an error in this question

Data Types & VariablesMedium

Q13. What is the difference between value types and reference types?

  1. A.Value types store data directly; reference types store a memory address✓ Correct
  2. B.They are completely identical in behavior and memory representation
  3. C.Value types are immutable and cannot be modified after creation
  4. D.Reference types always execute faster than value types at all times

Explanation

Value types hold data directly in memory, while reference types store a reference (address) to the data's location.

Report an error in this question

Data Types & VariablesMedium

Q14. What happens when you assign a float value to an int variable without casting?

  1. A.It works fine with no issues at all
  2. B.Compilation error in strongly typed languages✓ Correct
  3. C.The decimal part is automatically rounded up
  4. D.The program crashes with a runtime exception

Explanation

In strongly typed languages like Java, assigning a float to an int without explicit casting causes a compilation error.

Report an error in this question

Data Types & VariablesMedium

Q15. What is an enumeration (enum)?

  1. A.A looping construct for iteration
  2. B.A dynamically resizable array type
  3. C.A function for string manipulation
  4. D.A set of named constant values✓ Correct

Explanation

An enum defines a fixed set of named constants, improving code readability and type safety.

Report an error in this question

Data Types & VariablesMedium

Q16. What is the difference between signed and unsigned integers?

  1. A.There is no meaningful difference between signed and unsigned types
  2. B.Signed holds only positive values; unsigned holds negative values
  3. C.They have different byte sizes in memory but the same value range
  4. D.Signed holds negative and positive; unsigned holds non-negative only✓ Correct

Explanation

Signed integers can represent both negative and positive values, while unsigned integers represent only non-negative values.

Report an error in this question

Data Types & VariablesMedium

Q17. What is a nullable type?

  1. A.A type that is always null
  2. B.A type with no default value
  3. C.A type that cannot be null
  4. D.A type that can hold a value or null✓ Correct

Explanation

A nullable type can hold either a valid value of its underlying type or null, indicating the absence of a value.

Report an error in this question

Data Types & VariablesMedium

Q18. What is the result of integer overflow?

  1. A.The value automatically becomes null
  2. B.An exception is always thrown by runtime
  3. C.The program always crashes immediately
  4. D.The value wraps around in most languages✓ Correct

Explanation

In most languages, integer overflow causes the value to wrap around due to fixed bit representation.

Report an error in this question

Data Types & VariablesMedium

Q19. What is a union type in TypeScript?

  1. A.A built-in type for numeric calculations
  2. B.A type that can be one of several types✓ Correct
  3. C.A type that combines properties of two types
  4. D.A class that extends multiple parent classes

Explanation

A union type (e.g., string | number) allows a variable to hold a value of any of the specified types.

Report an error in this question

Data Types & VariablesMedium

Q20. What is type aliasing?

  1. A.Hiding a type from external modules
  2. B.Renaming a declared variable in scope
  3. C.Converting between different data types
  4. D.Creating a new name for existing type✓ Correct

Explanation

Type aliasing creates an alternative name for an existing type, improving readability (e.g., typedef in C, type in TypeScript).

Report an error in this question

Data Types & VariablesHard

Q21. What is the IEEE 754 standard?

  1. A.A specification for database schemas
  2. B.A standard for security encryption
  3. C.A protocol for computer networking
  4. D.A standard for floating-point numbers✓ Correct

Explanation

IEEE 754 defines the representation and behavior of floating-point numbers in computing, including special values like NaN and Infinity.

Report an error in this question

Data Types & VariablesHard

Q22. What is a phantom type?

  1. A.A type providing compile-time safety without storing data✓ Correct
  2. B.A type that has been deprecated from the language standard
  3. C.A type reserved for representing ghost or phantom objects
  4. D.A type that only exists at runtime and not at compile time

Explanation

Phantom types are type parameters that don't correspond to any runtime data but enforce constraints at compile time.

Report an error in this question

Data Types & VariablesHard

Q23. What is the difference between structural typing and nominal typing?

  1. A.They are exactly the same concept with different names
  2. B.Structural typing is only applicable to struct data types
  3. C.Nominal typing is only applicable to numeric data types
  4. D.Structural checks compatibility by shape; nominal by name✓ Correct

Explanation

Structural typing (e.g., TypeScript) considers types compatible if their structures match; nominal typing (e.g., Java) requires explicit declarations.

Report an error in this question

Data Types & VariablesHard

Q24. What is type erasure in Java generics?

  1. A.Removing type information at the compile stage
  2. B.Deleting all variables of a particular given type
  3. C.Generic type info removed at runtime as raw types✓ Correct
  4. D.Converting every type to Object at compile time

Explanation

Type erasure removes generic type information at runtime, replacing it with raw types and inserting casts as needed for backward compatibility.

Report an error in this question

Data Types & VariablesHard

Q25. What is a dependent type?

  1. A.A type that inherits from another
  2. B.A type that depends on a library
  3. C.A type that is defined by a value✓ Correct
  4. D.A type that requires garbage collection

Explanation

A dependent type is a type whose definition depends on a value, allowing more precise type specifications (e.g., a vector of length n).

Report an error in this question

Data Types & VariablesHard

Q26. What is the bottom type in type theory?

  1. A.A type with no values and subtype of every type✓ Correct
  2. B.The null type representing an absence of a value
  3. C.The base class that all other types inherit from
  4. D.The standard integer type used for whole numbers

Explanation

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.

Report an error in this question

Data Types & VariablesHard

Q27. What is variance in type systems?

  1. A.Random and unpredictable behavior in type inference
  2. B.The size variation of different data types in memory
  3. C.How subtyping of complex types relates to components✓ Correct
  4. D.The total range of values a type can hold

Explanation

Variance describes how subtyping of container/generic types relates to the subtyping of their type parameters (covariant, contravariant, invariant).

Report an error in this question

Data Types & VariablesHard

Q28. What is an algebraic data type (ADT)?

  1. A.An array type that exclusively stores numeric values
  2. B.A data type designed for mathematical operations only
  3. C.A type used for representing algebraic math expressions
  4. D.A composite type combining sum and product operations✓ Correct

Explanation

ADTs are composite types formed via sum types (tagged unions/enums) and product types (tuples/records), common in functional languages.

Report an error in this question

Data Types & VariablesHard

Q29. What is the unit type?

  1. A.A type with exactly one possible value✓ Correct
  2. B.A type used for measurement units
  3. C.The integer constant value of one
  4. D.A class with a single instance only

Explanation

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.

Report an error in this question

Data Types & VariablesHard

Q30. What is the purpose of type witnesses in advanced type systems?

  1. A.To provide explicit proof of type relationships✓ Correct
  2. B.To help debug complex type errors in code
  3. C.To convert types dynamically during execution
  4. D.To observe and log type changes at runtime

Explanation

Type witnesses are explicit terms that prove type equalities or relationships, helping the compiler verify complex type-level computations.

Report an error in this question

Ready to test yourself on Data Types & Variables?

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