Type inference: Difference between revisions
From Coderwiki
More actions
new: info, example |
(No difference)
|
Latest revision as of 21:37, 14 August 2025
Some programming languages can infer the data type of a variable based on the value that was assigned to the variable.
Importantly, this does not mean the value is untyped (like in dynamic typing), just that we don't need to specify the type because the compiler or interpreter can 'guess' the type.
Example of type inference
edit edit sourceBelow is an example of type inference in the Rust programming language. The two code snippets below are equivalent:
let x = 17;
let x: i32 = 17;
Many other programming languages have this features, such as C with its 'auto' keyword.