An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
November 20, 2020 05:48 am GMT
Original Link: https://dev.to/blender/type-safety-in-c-hhg
Type Safety in C
C++ enforces types, that means, every variable has a type and then that is its type forever and it can't be changed.
Expressions like 2 or 2+2 also have a type.
It is okay to "promote"
- put an integer (eg 2) into a float
The compiler will however warn you if you "demote" and throw away information
- put a floating point number (say 4.9) into an integer
This applies for variables initialised using auto as well.
Some combinations are just not allowed and will result in compiler errors
- put a string into an int
- multiply a string and a float
Please leave out comments with anything you don't understand or would like for me to improve upon.
Thanks for reading!
Original Link: https://dev.to/blender/type-safety-in-c-hhg
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To