Typecasting while outputting – CSKC
Sign In

Search

Code Learning #CPP#1747    siteicon   siteicon  

Typecasting while outputting

Type casting is often useful for manipulating display while outputting data.

Learning Objectives

  • Learning to manipulate the display of data while outputting using typecasting.

Source Code

TC++ #1747

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Code Understanding

int a=65; cout<<(char) a<<endl;
Here integer variable a is initialised with a value 65 which is ascii equivalent of uppercase A. while outputting we can print A by simply typecasting it as a (char) type.

float b=10.32; cout<<(int) b<<endl;
Here a float variable is initialised with 10.32. If we want to show the integer portion we can typecast is as an (int) to show only the value before the decimal point. So the output will come as 10.

Notes

  • Some times the precision of value may be affected when a data is type-casted. For e.g. typecasting a float value to a double number may display results different from the expected results.


Suggested Filename(s): output-cast.cpp



Share

Created: 16-Dec-2017 23:30 | Updated: 28-Aug-2018 15:48|