DEV Community

Cover image for Type Safety in Functions
Saloni Goyal
Saloni Goyal

Posted on • Edited on

3 1

Type Safety in Functions

C++ is a type safe language.

When you call a function, the parameters it takes have types. You provide the arguments and sometimes they need to be converted to the type of the parameters used. This conversion can be

  • possibly risky in which case the compiler will warn
  • passing a double (1.2) to a function which takes int parameter

The return value from the function might also be converted as part of assigning the value and this too could lead to compiler warnings if data is being thrown away.

Type safety rules apply everywhere in C++, from variables, to expressions as well as to functions.

Please leave out comments with anything you don't understand or would like for me to improve upon.

Thanks for reading!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (2)

Collapse
 
designeranna1 profile image
Designer Anna

Nice read. 👍
Plz provide a few examples or screenshots for better understanding .

Keep coding, keep growing.! ☕️

Collapse
 
blender profile image
Saloni Goyal

Thanks for the feedback Anna 😃, will surely do.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay