Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 20, 2020 05:48 am GMT

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

Alt Text

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To