C Expressions

Write a program for type conversion

#include<stdio.h>
void main()
{
	int a,b,
	Float div;
	printf(“Enter the value of a:/n”);
	scanf(“%d”,&a);
	printf(“Enter the value of b:/n”);
	scanf(“%d”,&b);
	div=a/b;
	printf(“ Division of a and b=%f”,div);
	getch();
} 
        


Type conversions in expressions: Implicit

C permits mixing of constants and variables of different types in an expression. C automatically converts any intermediate values to the proper type so that the expression can be evaluated without loosing any significance.
This automatic type conversion is know as implicit type conversion...
Given below is sequence of rules that are applied while evaluating expressions:
All short and char are automatically converted to int then
1. If one operand is long double, 
   the other will be converted to long double and result will be long double.
2. If one operand is double, 
   the other will be converted to double and result will be double.
3. If one operand is float, 
   the other will be converted to float and result will be float.
4. If one of the operand is unsigned long int, 
   the other will be converted into unsigned long int and result will be unsigned long int. 
5. If one operand is long int and other is unsigned int then 
 	a. If unsigned int can be converted to long int,
	   then unsigned int operand will be converted as such
	   and the result will be long int. 
	b. Else  Both operands will be converted to unsigned long int 
	   and the result will be unsigned long int. 
6. If one of the operand is long int, 
   the other will be converted to long int and the result will be long int.
7. If one operand is unsigned int the other will be converted 
   to unsigned int and the result will be unsigned int.
        


Make Comments..!!


Oops!! No posts from user.

Download Android App