All fields

“Operator Overloading” in Information Technology

54 questions across 3 technologies.

Information Technology

54 questions in 3 technologies

#QuestionTechnologyTopicLevel
1How do you overload the '+' operator to support adding two custom objects together? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingBeginner
2Which operators can be overloaded in C#, and which ones (like && and ||) generally CANNOT be overloaded directly? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingIntermediate
3How do you overload comparison operators like < and >, and what consistency rule must they maintain relative to Equals()? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingIntermediate
4How do you define a custom implicit or explicit conversion operator between your type and another type? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingIntermediate
5How do you overload arithmetic operators like + and - using __add__ and __sub__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
6How does __contains__ let you customize the behavior of the 'in' operator? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
7How do you overload the true/false operators to make a custom type usable directly in an 'if' statement or as a boolean condition? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingAdvanced
8How would you implement a fluent, chainable custom '+' operator overload for building an immutable Vector3 math library, and what performance consideration applies for structs? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingAdvanced
9How do you implement the 'checked' operator overload variant (introduced in C# 11) to provide overflow-checking behavior for a custom numeric type? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingAdvanced
10How do __iadd__ and other in-place operator methods (__isub__, __imul__) differ from their non-in-place counterparts? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
11What is the difference between __str__ and __repr__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingBeginner
12What is an indexer, and how does it let a custom class support square-bracket syntax like an array? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingBeginner
13What are 'magic methods' (dunder methods) in Python, and why are they called that? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingBeginner
14How does __repr__ help with debugging when printing a list of custom objects? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingBeginner
15What do __eq__ and __hash__ need to satisfy together, and what happens if you only override __eq__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
16How do __len__, __getitem__, and __setitem__ let a custom class act like a sequence or mapping? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
17How does __call__ let an instance of a class be invoked like a function? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
18How do comparison magic methods like __lt__, __le__, __gt__, and __ge__ support custom sorting? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
19How do you implement custom attribute access with __getattr__ versus __getattribute__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingIntermediate
20How would you implement a multi-dimensional indexer, like a Matrix class supporting matrix[row, col] syntax? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingAdvanced
21How would you use an indexer together with a custom enumerator (implementing IEnumerable) to build a fully iterable, indexable custom collection class? C# › Indexers & Operator OverloadingC#Indexers & Operator OverloadingAdvanced
22How do context manager magic methods __enter__ and __exit__ work, and what does __exit__'s return value control? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
23What is the difference between __new__ and __init__, and when would you override __new__? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
24How does __bool__ (or the legacy __nonzero__) determine an object's truthiness, and what's the fallback if it's not defined? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
25How does __slots__ interact with magic methods and instance attribute storage? Python › Magic Methods & Operator OverloadingPythonMagic Methods & Operator OverloadingAdvanced
26What is a user-defined conversion operator? C++ › Casting & ConversionsC++Casting & ConversionsAdvanced
27How do you overload operator<< for a custom type? C++ › I/O StreamsC++I/O StreamsAdvanced
28What are C++ I/O streams? C++ › I/O StreamsC++I/O StreamsBeginner
29What does the @dataclass decorator automatically generate for a class? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesBeginner
30What does the @property decorator do, and how does it let a method be accessed like an attribute? Python › Descriptors & PropertiesPythonDescriptors & PropertiesBeginner
31What is the difference between an iterable and an iterator in Python? Python › Iterators & the Iterator ProtocolPythonIterators & the Iterator ProtocolBeginner
32What is multiple inheritance in Python, and how does it differ from single inheritance? Python › Multiple Inheritance & MROPythonMultiple Inheritance & MROBeginner
33Why must dictionary keys (and set elements) be hashable, and what makes an object hashable in Python? Python › Data Types & StructuresPythonData Types & StructuresIntermediate
34How do you make a dataclass immutable (read-only after creation) using frozen=True? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesIntermediate
35How do you write a decorator as a CLASS instead of a function, implementing __call__? Python › DecoratorsPythonDecoratorsIntermediate
36What is a descriptor, and which dunder methods define the descriptor protocol? Python › Descriptors & PropertiesPythonDescriptors & PropertiesIntermediate
37What is the difference between a data descriptor and a non-data descriptor, and how does this affect attribute lookup priority? Python › Descriptors & PropertiesPythonDescriptors & PropertiesIntermediate
38How does __set_name__ let a descriptor automatically learn the attribute name it's being assigned to on the owning class? Python › Descriptors & PropertiesPythonDescriptors & PropertiesIntermediate
39How does @functools.wraps preserve metadata when writing decorators? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsIntermediate
40How does functools.total_ordering reduce boilerplate for comparison methods? Python › functools & Functional Programming ToolsPythonfunctools & Functional Programming ToolsIntermediate
41How does Python know whether to treat a for-in target as iterable, and what error occurs if it isn't? Python › Iterators & the Iterator ProtocolPythonIterators & the Iterator ProtocolIntermediate
42How does the built-in `object` class relate to every class's MRO, and why does it always appear last? Python › Multiple Inheritance & MROPythonMultiple Inheritance & MROIntermediate
43How do you overload a member function on const? C++ › Const CorrectnessC++Const CorrectnessAdvanced
44What is argument-dependent lookup (ADL)? C++ › NamespacesC++NamespacesAdvanced
45How do you implement type-safe bit flags with enum class? C++ › Enums & Enum ClassesC++Enums & Enum ClassesAdvanced
46How does frozenset differ from a regular set, and what specific use case does its immutability enable? Python › Data Types & StructuresPythonData Types & StructuresAdvanced
47How do you use dataclasses.field(compare=False) or field(repr=False) to exclude a specific field from the auto-generated __eq__ or __repr__? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesAdvanced
48How do you implement custom ordering (<, <=, >, >=) for a dataclass using order=True, and what constraint does it place on field comparison? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesAdvanced
49How do you implement a custom __eq__ or __hash__ on a dataclass while still benefiting from its other auto-generated methods? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesAdvanced
50How would you use dataclasses.replace() to create a modified copy of an immutable (frozen) dataclass instance? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesAdvanced
51When would you choose a NamedTuple over a @dataclass, and vice versa, given their overlapping use cases? Python › Dataclasses & NamedTuplesPythonDataclasses & NamedTuplesAdvanced
52How does Python's own implementation of instance methods use the descriptor protocol to achieve automatic 'self' binding? Python › Descriptors & PropertiesPythonDescriptors & PropertiesAdvanced
53How does __class_getitem__ enable generic-looking syntax like MyClass[int]? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationAdvanced
54How does __instancecheck__ and __subclasscheck__ on a metaclass enable 'virtual subclassing' as used by collections.abc? Python › Metaclasses & Class CustomizationPythonMetaclasses & Class CustomizationAdvanced