The conversion of the data type of the variable’s value into another data type during the program execution is called type casting. There are two standard ways to do type casting.
- Implicit type casting
- Explicit type casting
Implicit type casting
Implicit type casting is the one that can be performed automatically by the compiler during the program execution. In normal cases, the operands must be of similar data types. But If the data types of the operands are different then the values with lower data types are converted into higher data types. It is very important here to describe that the data types are categorized from higher-order to lower order. This classification of data types is based on the number of bytes that a data type takes in the memory. Different data types are arranged in the following higher to lower order.
1. Long Double
2. Double
3. Float
4. Long
5. Int
6. Char
In the above sequence Long double is of higher-level data type and the char is of lowest level data type. In nested parenthesis are applied, then the part of the expression in the innermost parenthesis is evaluated first.
Example:
int a;
double b;
a + b;
In the above piece of code, a is an integer type variable and b is a double type variable and we want to evaluate the expression a + b. In this expression, the data type of a is lower than b. Therefore, the value of a will be converted into double type implicitly by the compiler. The data type of a will remain the same. I.e, it remains int. Only the value is converted into another data type in order to evaluate the expression. This implicit type casting is all done automatically by the compiler itself.
Explicit type casting
Explicit type casting is done manually by the programmer or developer. In explicit type casting, the type cast operator is used. For example, convert one numeric data type into another numeric data type. Here is the simple syntax for the explicit type casting.
(type) expression;
Type: It specifies the data type to which the value of the expression is to be converted.
Expression: Expression includes a constant, variable, or maybe an expression whose data type is to be converted.
Example:
float a;
float b;
a % b;
In this above piece of code, we can see that both variables a and b are of float type. And once we run the expression a % b, it will generate a runtime error because the modulus operator can only work with integers. So in that case, the modulus operator can’t work with float variables. So the value of both the variables must be converted explicitly into an int data type.
(int) a % (int) b;
The above expression will convert the values of variable a and value of variable b into an int data type. By doing this, the above expression can be evaluated successfully. Like in the implicit type casting, it is important to explain that the values of both the variables a and b are temporarily converted while the actual data type remains float according to the above-mentioned example.
Do you mind if I quote a couple of your posts as long as I provide credit and sources back to
your blog? My blog is in the exact same area of interest as yours and
my users would definitely benefit from some of the information you provide here.
Please let me know if this okay with you. Thank you!
Yes you can do that
Quality articles or reviews is the key to be
a focus for the people to pay a visit the website, that’s what this web site is
providing.
Thanks for every other informative blog. The place else may just I am getting that type of
information written in such an ideal method?
I’ve a project that I am just now operating on, and I have been at the look out for such
info.
Hello! This is my first visit to your blog! We are a
collection of volunteers and starting a new initiative in a community in the same niche.
Your blog provided us useful information to work on. You
have done a outstanding job!
I do not even know how I ended up here, but I thought this post was great.
I do not know who you are but definitely you are going to a famous blogger if you
aren’t already 😉 Cheers!
Spot on with this write-up, I seriously feel this site needs far more attention. I’ll probably be returning to read through more, thanks for the info!
Hello my family member! I want to say that this article is awesome, nice written and
include almost all important infos. I’d like to peer more posts like this .
I was very pleased to find this web site. I
want to to thank you for ones time just for this wonderful read!!
I definitely really liked every part of it and i also have you book-marked to look at new information in your
website.
There’s certainly a lot to learn about this topic.
I really like all the points you made.
You’ve made some good points there. I looked on the
web for additional information about the issue and found most individuals will go
along with your views on this website.
Today, I went to the beachfront with my children. I found a sea shell and
gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
There was a hermit crab inside and it pinched her ear. She never wants to go back!
LoL I know this is completely off topic but I
had to tell someone!
I do not even know how I ended up here, but I thought
this post was great. I don’t know who you are but definitely you are going
to a famous blogger if you aren’t already 😉
Cheers!
An impressive share! I have just forwarded this onto a friend who had been doing a little homework on this.
And he actually bought me dinner due to the fact that I stumbled upon it for him…
lol. So allow me to reword this…. Thank YOU for the meal!!
But yeah, thanx for spending some time to talk about this topic
here on your web site.
I have been exploring for a little for any high-quality articles or blog posts
on this sort of space . Exploring in Yahoo I eventually stumbled upon this website.
Reading this info So i’m glad to convey that I have an incredibly
excellent uncanny feeling I came upon just what I needed.
I such a lot unquestionably will make sure to don?t fail to remember this
site and provides it a glance on a relentless basis.
Hurrah, that’s what I was seeking for, what a data!
present here at this web site, thanks admin of this site.
I am actually thankful to the owner of this site who has shared this impressive article at here.
certainly like your web site however you have to test the spelling on quite a few of your
posts. Several of them are rife with spelling problems
and I in finding it very troublesome to tell the truth then again I’ll certainly
come again again.
Howdy! I simply want to offer you a big thumbs up for the excellent info you have got here on this post.
I’ll be coming back to your website for more soon.
Having read this I thought it was really enlightening. I appreciate you spending some time and effort to put this short article together.
I once again find myself personally spending way too much time
both reading and leaving comments. But so what, it was still worth it!
We stumbled over here coming from a different web page
and thought I should check things out. I like what I see
so i am just following you. Look forward to looking into your web page
repeatedly.
Hi! I’m at work browsing your blog from my new iphone!
Just wanted to say I love reading your blog and look forward to all your posts!
Carry on the outstanding work!
whoah this weblog is fantastic i really like studying your articles.
Keep up the good work! You realize, many persons are hunting around for
this information, you can aid them greatly.
Saved as a favorite, I really like your blog!
You are so interesting! I don’t believe I’ve read through a single
thing like this before. So good to discover another person with a
few genuine thoughts on this subject. Seriously.. thank you for starting this up.
This site is something that is needed on the internet, someone with a bit
of originality!
I do not even know how I ended up here, but I thought this post was great.
I do not know who you are but certainly you’re going to a famous blogger if you aren’t already 😉 Cheers!
My partner and I stumbled over here coming from a different
page and thought I might as well check things out.
I like what I see so now i am following you. Look forward to checking out your web page yet again.
I’m not that much of a online reader to be honest but your sites really
nice, keep it up! I’ll go ahead and bookmark your site
to come back in the future. Many thanks
It’s actually a cool and helpful piece of info.
I am happy that you shared this useful information with
us. Please keep us informed like this. Thanks for sharing.
Thankfulness to my father who shared with me on the topic of this website, this web site is
genuinely amazing.
Wonderful beat ! I would like to apprentice while you amend your web site, how
can i subscribe for a blog web site? The account helped me a acceptable deal.
I had been a little bit acquainted of this your broadcast provided bright
clear concept
Hi to all, the contents present at this site are
really remarkable for people experience, well, keep up the nice work fellows.
Hello, I think your blog might be having browser compatibility issues.
When I look at your blog in Safari, it llooks fine but when opening in Internet Explorer,
it has some overlapping. I just wanted to give yoou a quick heads up!
Other then that, amazing blog!
Howdy! This blog post couldn’t be written any better!
Reading through this post reminds me of my previous roommate!
He continually kept talking about this. I will send this information to him.
Fairly certain he will have a good read. Thank you
for sharing!
I’ve learn some excellent stuff here. Certainly worth bookmarking for revisiting.
I wonder how so much effort you set to make the sort of fantastic informative
website.