Elementary Data Types MCQ Questions and Answers
1. In programming languages, the type of a value primarily defines:
A) the memory address where the value is stored
B) the set of possible values and operations allowed on that value
C) the color to display the value in an IDE
D) the method names associated with the value
[Answer: B]
2. The property of a type that determines whether a variable of that type may change after initialization is called:
A) mutability
B) polymorphism
C) encapsulation
D) inheritance
[Answer: A]
3. Which of the following is a scalar data type?
A) Array
B) Record (struct)
C) Integer
D) Tuple
[Answer: C]
4. A composite data type is best characterized by:
A) containing only primitive numeric values
B) being defined by a single atomic value
C) being composed of multiple elements, possibly of different types
D) having no operations defined on it
[Answer: C]
5. Which of these is an example of a primitive (elementary) type in many languages?
A) HashMap
B) Float
C) Class
D) Interface
[Answer: B]
6. The difference between static typing and dynamic typing relates to:
A) whether the program uses recursion
B) timing of type checking (compile-time vs run-time)
C) the physical memory allocation method
D) the order of function calls
[Answer: B]
7. In strong vs. weak typing, strong typing typically means:
A) the language forbids any type conversions at runtime
B) type errors are less likely because implicit conversions are restricted
C) only scalar types exist
D) memory use is minimized
[Answer: B]
8. Which property of objects indicates how long values of that object live (allocation lifetime)?
A) visibility
B) lifetime (storage duration)
C) polymorphism
D) mutability
[Answer: B]
9. An abstract data type (ADT) differs from a concrete data type mainly because:
A) ADT includes implementation details like memory layout
B) ADT specifies behavior and operations but not implementation
C) ADT is always immutable
D) ADT cannot be implemented in object-oriented languages
[Answer: B]
10. Which is an example of a composite homogeneous data structure?
A) Tuple with (int, float, string)
B) Array of integers
C) Record with fields of different types
D) Union of different types
[Answer: B]
11. A heterogeneous collection permits:
A) only integers
B) different types in the same aggregate
C) only floating-point values
D) only built-in types
[Answer: B]
12. In languages with explicit pointer types, the pointer type describes:
A) the operations that can be called on the value pointed to
B) the type of the address itself and the target value type
C) the file descriptor associated with the value
D) the class inheritance tree
[Answer: B]
13. Which of the following best describes range as a type property?
A) the number of methods available on the type
B) constraints on the set of values (e.g., min and max) the type allows
C) the scope visibility of the type declaration
D) the type’s memory alignment requirements
[Answer: B]
14. Which is a nominal typing discipline feature?
A) compatibility determined by structure (shape) of types
B) compatibility determined by explicit names (declarations) of types
C) types computed at runtime by introspection only
D) types inferred automatically without names
[Answer: B]
15. Which is a characteristic of structural typing?
A) Type compatibility if and only if names match exactly
B) Type compatibility based on the structure (members and signatures)
C) Only used in dynamically typed languages
D) Prevents subtyping entirely
[Answer: B]
16. Immutable scalar types provide which primary benefit?
A) Faster I/O operations
B) Easier reasoning about program state and thread-safety
C) Reduced compile-time checking
D) Unlimited range of values
[Answer: B]
17. Which composite type allows variable-length aggregation and typically supports indexing?
A) Linked list only
B) Array with fixed length only
C) Sequence (like array or list)
D) Enum
[Answer: C]
18. In the context of types, aliasing refers to:
A) giving a new name to an existing type without new semantics
B) renaming variables during optimization
C) hiding a method name in inheritance
D) creating an unrelated new type with same size
[Answer: A]
19. Which of the following is an example of a derived type?
A) Integer
B) Float
C) Pointer to integer
D) Boolean
[Answer: C]
20. Which property primarily concerns how bits are laid out in memory for a type?
A) semantic model
B) representation (physical layout)
C) documentation string
D) operator overloading rules
[Answer: B]
21. Which of these operations is usually not part of the type’s interface but part of the language’s runtime?
A) addition for integers
B) garbage collection for objects
C) concatenation for strings
D) comparison for booleans
[Answer: B]
22. In languages with type inference, which is true?
A) The programmer must always annotate every variable with its type
B) Compiler can often deduce type from usage without explicit annotation
C) Types are checked only at runtime
D) There is no static type-checking at all
[Answer: B]
23. A union (as a composite type) typically allows:
A) storing different types in the same storage location but treating them as the declared variant
B) only storing multiple elements of same type
C) memory-only read operations
D) thread-safe mutation by default
[Answer: A]
24. Which of the following is a typical reason for distinguishing type and object in language design?
A) Types manage runtime threads while objects do not
B) A type is a classification (set of values and operations), whereas an object is an instance/value that inhabits a type
C) An object defines syntax, while type defines semantics
D) Types are only compile-time and objects only exist in dynamic languages
[Answer: B]
25. Which type property is most relevant when implementing numeric computations that must be portable across platforms?
A) method names
B) representation and precision (e.g., IEEE 754)
C) variable naming conventions
D) IDE settings
[Answer: B]
26. Which composite type typically provides named fields?
A) Array
B) Record (struct)
C) Primitive integer
D) Enum constant
[Answer: B]
27. In many languages, an enumeration (enum) type primarily represents:
A) a collection of floating-point values
B) a finite set of named constant values
C) an unbounded container of heterogeneous values
D) a function pointer table
[Answer: B]
28. Which of these is a common property of string types in many languages?
A) they always have fixed-size storage equal to 8 bytes
B) they support sequences of characters and usually length information
C) they are always composite of integers only
D) they are identical to arrays of booleans
[Answer: B]
29. The width of an integer type refers to:
A) how many operations it supports
B) the number of bits used to represent values
C) the number of methods in its class
D) the number of parameters a function accepts
[Answer: B]
30. Endianness is a property that affects:
A) how functions are named
B) the order of bytes in memory representation of multi-byte types
C) the speed of arithmetic operations only
D) scoping rules in modules
[Answer: B]
31. Which of the following is a first-class value in languages where it applies?
A) only classes can be passed around as values
B) values that can be passed as arguments, returned from functions, and assigned to variables (e.g., functions in first-class function languages)
C) only immutable values
D) only language keywords
[Answer: B]
32. Which of these describes boxing in the context of types?
A) storing values in a special heap object to treat a primitive as an object
B) preventing further inheritance from a class
C) compressing data to save disk space
D) encrypting values for security
[Answer: A]
33. When a language provides unboxed representation for scalar values, it typically means:
A) values are stored with additional metadata in the heap
B) scalar values are stored directly (no extra object wrapper) for efficiency
C) values cannot be passed between functions
D) the language prohibits arithmetic
[Answer: B]
34. Which property allows a composite type to be iterated (e.g., in a for loop)?
A) having a visible name
B) implementing an iterable interface or providing an iterator protocol
C) being immutable
D) fixed-size memory layout only
[Answer: B]
35. Which best describes subtyping?
A) creating an entirely unrelated type with the same name
B) a relationship where values of one type can be used where another (super)type is expected
C) conversion of types through bitwise operations only
D) storing types in separate namespaces only
[Answer: B]
36. A structural subtyping example is:
A) an object type named “A” equals type named “B” only if names match
B) type S usable where T is expected if S has at least the operations and fields T requires
C) subtyping only via explicit casts
D) subtyping prohibited in all typed languages
[Answer: B]
37. Which of the following is a property of objects in object-oriented languages?
A) they never have state
B) they encapsulate state (fields) and behavior (methods)
C) they cannot be passed to functions
D) they always map directly to hardware registers
[Answer: B]
38. The operation of type promotion usually refers to:
A) allowing smaller numeric types to be converted to larger ones automatically in expressions
B) increasing access privileges of a variable
C) giving a type a new name
D) moving variables from stack to heap at runtime
[Answer: A]
39. Which scalar type is commonly used to represent truth values?
A) Integer
B) String
C) Boolean
D) Array
[Answer: C]
40. In languages with strong static typing, which is most likely true?
A) type errors are caught at compile-time and there are few automatic runtime coercions
B) program execution continues even with type errors unchecked
C) types cannot be declared by programmers
D) runtime is significantly slower without reason
[Answer: A]
41. A tagged union differs from an untagged union by:
A) storing extra metadata (a tag) to identify which variant is active
B) preventing storage of multiple types
C) only allowing numeric variants
D) having fixed-size array semantics
[Answer: A]
42. Which composite type is ideal for representing a mapping from keys to values?
A) Stack
B) Queue
C) Dictionary / Map / HashMap
D) Tuple
[Answer: C]
43. Which of these is a language-level type property affecting how equality is defined?
A) identity vs structural equality semantics (whether equality checks same object or same contents)
B) the file permissions of the source file
C) the font used in the editor
D) the physical CPU architecture only
[Answer: A]
44. Which property matters when considering whether two objects share the same memory?
A) aliasing and identity
B) whether the objects were printed before
C) the variable names used in the program
D) the file size of the source code
[Answer: A]
45. Which of the following best defines a sequence type?
A) fixed-depth binary tree only
B) an ordered collection of elements accessible by position/index
C) unordered mapping of keys to values
D) a single scalar masked by metadata
[Answer: B]
46. The term arity for a type of function refers to:
A) the number of methods on a class
B) the number of arguments a function takes
C) the memory footprint of return value
D) the type category (scalar/composite) only
[Answer: B]
47. Which data type property directly affects serialization (marshalling) behavior?
A) representation/layout and whether pointers or references are allowed
B) IDE color scheme
C) number of blank lines in source file
D) operator overloading only
[Answer: A]
48. Which of the following best describes call-by-value with respect to objects?
A) the callee receives a reference to the caller’s variable name only
B) the callee receives a copy of the value (which may be a reference) so reassignments in callee don’t affect caller’s binding
C) the callee can always mutate the caller’s variable binding directly
D) it only applies to numeric types
[Answer: B]
49. Which statement about type safety is correct?
A) type safety guarantees programs never crash
B) type safety reduces certain classes of runtime errors related to improper use of values across incompatible types
C) type safety is irrelevant in high-level languages
D) type safety means the language cannot support polymorphism
[Answer: B]
50. Which type is typically used to represent a user-defined fixed list of named constants along with possible methods in many languages?
A) Enum (enumeration)
B) Floating point
C) Pointer
D) Anonymous union
[Answer: A]
51. Which is a common advantage of composite types over many separate scalar variables?
A) increased compile-time only overhead
B) improved grouping and abstraction, easier to pass and manage related data
C) inability to be serialized
D) lack of indexing capabilities
[Answer: B]
52. Which of the following is true about nullable types?
A) nullable types prevent any value from ever being null
B) nullable types allow an extra “null” value indicating absence of value
C) nullable types are always integer-only
D) nullable types disallow pointer usage
[Answer: B]
53. The size (in bytes) of a type is governed by:
A) only compiler flags, never by the type definition
B) the type’s representation, alignment, and sometimes platform ABI rules
C) whether the programmer likes the type
D) only the number of methods attached to the type
[Answer: B]
54. In a language that uses value semantics for a composite type, assignment copies:
A) only a reference to underlying storage
B) the whole value (a deep or shallow copy depending on language rules), so each variable has its own storage
C) method implementations only
D) irrelevant metadata
[Answer: B]
55. Which composite type is usually best-suited for constant-time insertions and deletions at both ends?
A) Binary tree
B) Deque (double-ended queue)
C) Static array of fixed length
D) Enumeration
[Answer: B]
56. Which of these is NOT normally a property of types in statically-typed languages?
A) compile-time known constraints on operations
B) runtime type mutation (changing a variable’s declared type at runtime)
C) richer tooling (autocomplete, refactoring) due to known types
D) earlier detection of some errors
[Answer: B]
57. Which of the following is a primary motivation for using algebraic data types (ADTs) in languages that support them?
A) to encode multiple variants (sum types) and combinations (product types) with type-safe pattern matching
B) to avoid having multiple constructors
C) to only use integers internally
D) to improve binary I/O speed exclusively
[Answer: A]
58. Which of these best describes coercion?
A) a forced or implicit conversion between types performed by the language
B) a process of encrypting sensitive values
C) removal of unused fields from a struct
D) a type of loop construct
[Answer: A]
59. Which scalar type would typically provide fractional arithmetic?
A) Integer
B) Float / Real / Double
C) Enum
D) Boolean
[Answer: B]
60. When a type provides operator overloading, it means:
A) the type prevents any operation from being applied
B) developers can define custom behavior for standard operators (like + or *) for that type
C) operators become ineffective in the language
D) only built-in operators are supported, never user-provided
[Answer: B]
61. Which of the following is a typical property of an array type in many languages?
A) cannot be indexed
B) elements are stored in contiguous memory locations (for arrays)
C) always heterogeneous by element type
D) has no length information anywhere
[Answer: B]
62. Which type of composite is best for representing tree-like hierarchical data with parent-child relationships?
A) flat array only
B) linked nodes forming a tree (trees are composite types built from node structures)
C) enumeration only
D) scalar boolean
[Answer: B]
63. In a language with automatic memory management, which is typically true?
A) programmer must manually free every object
B) runtime automatically reclaims unreachable objects (garbage collection)
C) memory use cannot grow dynamically
D) only scalar types are garbage-collected
[Answer: B]
64. Which of these describes an opaque type?
A) the type exposes all its internal fields publicly
B) the type’s internal representation is hidden from clients; operations are provided instead
C) the type cannot be instantiated ever
D) the type is always mutable by default
[Answer: B]
65. Which concept is central to parametric polymorphism (generics)?
A) types depend on runtime values only
B) writing code that works uniformly for any type parameter supplied (type-parameterized code)
C) forbidding reuse of code across types
D) ensuring only integers can be used in generic code
[Answer: B]
66. Which of these statements about type erasure in generics is correct?
A) type information for generics is always preserved fully at runtime in all languages
B) type erasure removes generic type parameters at runtime, making runtime type checks less specific
C) type erasure increases runtime type safety
D) type erasure applies only to integer arithmetic
[Answer: B]
67. The alignment of a type affects:
A) how strings compare lexicographically
B) memory addresses at which values of that type prefer to be stored for efficient access
C) the public API naming convention
D) the number of available constructors
[Answer: B]
68. Which of the following is a reason to use immutable composite types?
A) to allow uncontrolled shared mutation across threads
B) to make reasoning about program state simpler and enable safe sharing without locks
C) to prevent any form of copying
D) to hide types from the linker
[Answer: B]
69. A flat memory representation of a composite means:
A) the composite is stored in multiple scattered memory blocks only
B) related values are stored in a single contiguous block (no extra pointers)
C) the composite cannot be serialized
D) the composite must be of integer type only
[Answer: B]
70. Which of the following is true about references (as opposed to pointers in some languages)?
A) references are always numeric types
B) references are language-level aliases to objects and may not support arithmetic like pointers do
C) references always require manual deallocation
D) references and pointers are identical in all respects in every language
[Answer: B]
71. Which property distinguishes a shallow copy from a deep copy?
A) shallow copy duplicates all reachable objects recursively, deep copy only references top-level object
B) shallow copy copies only top-level object and references the same nested objects; deep copy duplicates nested objects as well
C) shallow copy is only possible for scalar types
D) deep copy shares all storage with original
[Answer: B]
72. Which composite type is most commonly used to implement adjacency lists for graphs?
A) Set only
B) List/array of lists (or maps) — a composite-of-composites structure
C) Primitive integer only
D) Enum array only
[Answer: B]
73. Which of these is an example of a dependent type feature (in languages that support dependent types)?
A) types that depend on values (e.g., array length included in the type)
B) types that never reference runtime values
C) types only usable at runtime, not compile-time
D) types that reduce code reuse always
[Answer: A]
74. When a language provides value classes or inline classes, the intention is often:
A) to ensure all values are boxed on the heap
B) allow small user-defined types that can be represented without object header overhead (unboxed)
C) prohibit arithmetic operations on them
D) make serializing impossible
[Answer: B]
75. Which of the following best describes dependent object types in object systems?
A) object types that contain references to external file descriptors only
B) types that may depend on runtime values or parameters to form more precise types for members
C) types that cannot be instantiated ever
D) types solely used for GUI rendering
[Answer: B]
76. Which composite type is appropriate for LIFO behavior?
A) Queue
B) Stack
C) Set
D) Map
[Answer: B]
77. Which of the following properties is most relevant when deciding whether two types are compatible for assignment in a structural typing system?
A) whether their names are different
B) whether one type has at least the fields and method signatures the other expects (compatibility by structure)
C) the length of their source files
D) whether one is declared after the other in code ordering
[Answer: B]
78. Which of the following describes representation independence as a desirable property?
A) client code cannot rely on internal layout and only uses abstract operations, so implementation can change without breaking clients
B) internal layout is always exposed to clients
C) representation independence forbids any optimization
D) it requires every type to be immutable
[Answer: A]
79. Which of these is commonly a runtime check in many languages rather than a compile-time check?
A) malformed source code syntax
B) dynamic type casts and downcasts validity (e.g., checking actual runtime type)
C) missing semicolons
D) variable declaration absence at top-level only
[Answer: B]
80. Which scalar type best models discrete enumerated values that are not combined arithmetically?
A) Integer only
B) Enum / Symbol / Atoms (language-dependent)
C) Floating point only
D) Bitfield only
[Answer: B]
81. Which composite type is commonly used to return multiple values from a function in a single object?
A) Scalar boolean only
B) Tuple or record
C) Enum only
D) Pointer only
[Answer: B]
82. Which is an important consideration when using pointers inside composite structures?
A) pointers never affect memory layout
B) pointers introduce indirection, may affect locality, lifetime, and safety (dangling pointers)
C) pointers are always cheaper than inline embedding
D) pointers require special syntax to be declared as composite types
[Answer: B]
83. The least upper bound (join) in type systems is often used for:
A) deciding naming conventions in code
B) computing the minimal common supertype when inferring types of conditional expressions
C) calculating memory alignment value only
D) converting strings to integers automatically
[Answer: B]
84. Which of the following is a disadvantage of excessively large composite objects?
A) increased locality and cache friendliness always
B) higher memory footprint and possible performance overhead when copying or passing by value
C) guarantees of thread-safety automatically
D) elimination of need for garbage collection
[Answer: B]
85. Which of these describes phantom types usage?
A) to carry compile-time-only information that has no runtime representation, enabling extra type safety without runtime cost
B) to create ghosts in memory
C) to encrypt type names at compile-time
D) to reduce compile-time checks to zero
[Answer: A]
86. Which of the following is a common benefit of having precise type definitions in APIs?
A) more runtime surprises for clients
B) clearer contracts, enabling compile-time checking and easier maintenance
C) impossible to change the implementation ever
D) fewer compiler optimizations available always
[Answer: B]
87. Which of the following is typically not allowed for immutable composite values after construction?
A) adding new elements (mutation)
B) reading elements
C) hashing (for stable hashes)
D) comparing for equality
[Answer: A]
88. Which property of composite types affects whether two structurally equal composites may nonetheless be considered distinct objects?
A) identity vs equality semantics (object identity distinguishes them even if contents equal)
B) the number of nested loops using them
C) the editor used to define the type
D) the color of their variable names in source code
[Answer: A]
89. Which technique is commonly used to implement efficient string concatenation in languages with immutable strings?
A) always copying entire strings on each concatenation only
B) rope or buffer builder (deferred concatenation / tree of chunks)
C) disallowing concatenation
D) reversing strings permanently
[Answer: B]
90. In typed functional languages, sum types are useful to:
A) represent only numeric sums
B) represent a value that may be one of several different tagged variants (like union plus tag)
C) avoid any pattern matching constructs
D) represent only strings
[Answer: B]
91. Which is a typical reason for languages to provide fixed-size vs variable-size array types?
A) fixed-size arrays never improve performance
B) fixed-size arrays allow certain compile-time optimizations and known memory footprint; variable-size arrays allow flexible runtime sizing
C) variable-size arrays cannot be indexed
D) only fixed-size arrays can contain references
[Answer: B]
92. Which of the following best expresses the notion of data locality for composite types?
A) how many different programmers wrote the code for the type
B) how close in memory the parts of a composite are stored — affects cache performance
C) the geographic location of the data center storing the code
D) color scheme of the IDE used to view the composite type
[Answer: B]
93. Which of the following is a common constraint on elements of array types in statically-typed languages?
A) each element must have a different type
B) all elements are of a single declared element type (homogeneous)
C) elements cannot be compared
D) arrays cannot be iterated
[Answer: B]
94. Which composite structure allows associative collection with unique keys and typically supports fast lookup?
A) Stack
B) Hash table / Map
C) Array with only numeric indexes
D) Linked list without keys
[Answer: B]
95. Which of the following best describes lazy composite initialization?
A) initializing entire composite fully at startup always
B) deferring creation or computing of parts until they are first accessed to save resources
C) forbids any runtime creation of parts
D) always forces deep copying of nested elements
[Answer: B]
96. Which of the following is a property of bitfields in composite types?
A) they store values using a full word per field always
B) they pack multiple small integral fields into fewer bits to save space, often with implementation-specific layout rules
C) they are always portable and identical across platforms without caution
D) they cannot be used for flags or boolean combinations
[Answer: B]
97. Which of these is a correct statement about type completeness in a type system?
A) a complete type system supports reasoning about a wide class of programs, but “complete” has formal meanings depending on the property (e.g., soundness and expressiveness trade-offs)
B) completeness always means the type checker can prove every true program property automatically
C) type completeness is unrelated to languages at all
D) it requires no run-time type checks ever
[Answer: A]
98. Which of the following is often necessary to safely share mutable composite objects across threads?
A) never using locks or synchronization
B) synchronization primitives or making the composite immutable (to avoid data races)
C) relying on editor settings only
D) increasing the stack size of all threads only
[Answer: B]
99. Which of these best represents the concept of struct packing for composite types?
A) adding extra padding bytes between fields always
B) controlling or compressing alignment and padding to minimize memory footprint, possibly at cost of access speed or portability
C) changing the type of fields to boolean only
D) serializing the composite to a text file automatically
[Answer: B]
100. Which property is most important when designing an API that returns composite structures to external callers?
A) keeping the exact internal representation exposed so callers can rely on it forever
B) providing an abstract, stable interface and documentation to avoid breaking changes while allowing internal representation changes
C) forbidding any form of copying or passing of the composite
D) requiring callers to read the source code to use the API
[Answer: B]
