
- Forum
- Programming Talk
- C and C++
- Is this Program Correct
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() ...
-
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?
-
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.

Reply With Quote





