Results 1 to 5 of 5

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

  1. #1
    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.

  2. #2
    Join Date
    May 2009
    Posts
    542

    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

  3. #3
    Join Date
    May 2009
    Posts
    546

    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

  4. #4
    Join Date
    May 2009
    Posts
    640

    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.

  5. #5
    Join Date
    May 2009
    Posts
    527

    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.

Similar Threads

  1. Casting int to float in C
    By Jensen Ackles in forum Software Development
    Replies: 4
    Last Post: 05-04-2010, 05:08 PM
  2. Difference between Implicit & Explicit type conversions
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 09-02-2010, 01:47 PM
  3. Type Casting in Java
    By Aakarshan.d in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 01:56 PM
  4. What is type conversion and casting?
    By Jagriti in forum Software Development
    Replies: 3
    Last Post: 24-11-2009, 10:38 AM
  5. Difference between Implicit and Explicit Declaration
    By vinodpathak_214 in forum Software Development
    Replies: 3
    Last Post: 16-01-2009, 09:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •