Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is difference between implicit type casting and explicit type casting in C++?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 01-01-2011
Member
 
Join Date: Dec 2010
Posts: 11
What is difference between implicit type casting and explicit type casting in C++?
  

Hey guys, I want to know that, what is difference between implicit type casting and explicit type casting in C++? I am confused with this terms as I am not able understand this terms. I tried to understand these terms from books, my friends but still I am not able to get it. I find it very difficult. If anyone having any information about this term that please let me know as soon as possible.

Reply With Quote
  #2  
Old 01-01-2011
Member
 
Join Date: May 2009
Posts: 528
Re: What is difference between implicit type casting and explicit type casting in C++?

I think that you must be aware of the term type casting Some time it is the requirement of the program to store value of variable which is of float type into a variable which may be of int type, in such cases the data is to be converted from float to int. Conversion of data from one form to another form is known as type casting. C++ has two different type of casting.
1) Implicit type casting
2) Explicit type casting
Reply With Quote
  #3  
Old 01-01-2011
Member
 
Join Date: May 2009
Posts: 523
Re: What is difference between implicit type casting and explicit type casting in C++?

When we are performing any operation between variables the variable will be converted to the data type having higher range automatically. Promotion of data type from low range to high range automatically is known as implicit type casting.

For example
int a,c;
float b
c=a*b;
In above example when the multiplication operation is performed on the variable a and b implicit type casting will be performed by c++. Here the data type of a is int and that of b is float ,so when we are performing multiplication of a and b, the variable a will be promoted to float data type and then the operation will be performed .The result which will be of type float will be again casted to int type and then stored in variable c, causing lost of precision value
Reply With Quote
  #4  
Old 01-01-2011
Member
 
Join Date: May 2009
Posts: 602
Re: What is difference between implicit type casting and explicit type casting in C++?

When we are performing any operation between variables the variable will be converted automatically from one data type to another. But when the user want to convert data from one form to another then this type of conversion is known as explicit type casting. Explicit type casting can be achieved by writing the conversion data type before the variable or expression in brackets.
Reply With Quote
  #5  
Old 01-01-2011
Member
 
Join Date: May 2009
Posts: 518
Re: What is difference between implicit type casting and explicit type casting in C++?

For example
int a;
char c;
float b
c=(char)a*b;

In above example when the multiplication operation is performed on the variable a and b implicit type casting will be performed by c++. Here the data type of a is int and that of b is float ,so when we are performing multiplication of a and b, the variable a will be promoted to float data type and then the operation will be performed .The user may want to store the result which is of type float to store in character variable c. To achieve that user has to write (char) before the expression. This will convert the result into character data type and store in variable c.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is difference between implicit type casting and explicit type casting in C++?"
Thread Thread Starter Forum Replies Last Post
Casting int to float in C Jensen Ackles Software Development 4 05-04-2010 05:08 PM
Difference between Implicit & Explicit type conversions Sarfaraj Khan Software Development 5 09-02-2010 01:47 PM
Type Casting in Java Aakarshan.d Software Development 5 21-01-2010 01:56 PM
What is type conversion and casting? Jagriti Software Development 3 24-11-2009 10:38 AM
Difference between Implicit and Explicit Declaration vinodpathak_214 Software Development 3 16-01-2009 09:00 AM


All times are GMT +5.5. The time now is 07:18 PM.