Exforsys
+ Reply to Thread
Results 1 to 2 of 2

Is this Program Correct

This is a discussion on Is this Program Correct within the C and C++ forums, part of the Programming Talk category; I have a doubt about typecasting in C. I have the below code written in my program #include <stdio.h> main() ...

  1. #1
    cyrus is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    128

    Is this Program Correct

    I have a doubt about typecasting in C. I have the below code written in my program

    #include <stdio.h>
    main()
    {
    int x = 101;
    char y;
    y = x;
    }

    Is the above code correct that will C do automatic typecasting as assumed above in my code or do programmers have to do typecasting explicitly? If so I have to change my code. Kindly clarify my doubt?


  2. #2
    sammy is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    145
    This will not get automatically typecast as you have mentioned in your program. Automatic typecasting takes place in C but not as you have mentioned. Say for instance you have placed a variable x in a if statement then depending on the value of variables as 0 or 1 the conditional takes up status as false or true respectively. Whenever data type need to be changed you must use explicit typecasting in C programming language with the data type mentioned in brackets.


Latest Article

Network Security Risk Assessment and Measurement

Read More...