Questions Concepts
GitHub icon

Type Casting

Type Casting - language feature

< >
Example from C, C++, Objective-C, Tick C:
double da = 3.3; double db = 3.3; double dc = 3.4; int result = (int)da + (int)db + (int)dc; //result == 9
Example from MATLAB:
b = cast(a, 'like', p)
Example from C#:
Animal animal = new Cat(); Bulldog b = (Bulldog) animal; // if (animal is Bulldog), stat.type(animal) is Bulldog, else an exception b = animal as Bulldog; // if (animal is Bulldog), b = (Bulldog) animal, else b = null animal = null; b = animal as Bulldog; // b == null
Example from C3:
double d = 3.3; int x = (int)d;
Example from Speedie:
|| x = message() || y = x|object| // lose type info || z = y|message| // regain it
Example from Jule:
let x = (int)(3.14)

Languages with Type Casting include C, C++, MATLAB, C#, TypeScript, Objective-C, C3, Speedie, Jule, Tick C, Static Typescript

This question asks: Does the language have a syntax for type casting?

Read more about Type Casting on the web: 1.

HTML of this page generated by Features.ts

View source

- Build the next great programming language Search Add Language Features Creators Resources About Blog Acknowledgements Queries Stats Sponsor Traffic Traffic Today Day 305 Logout