## Wednesday, 30 January 2019

1.a) Differentiate post increment and pre increment operator. {WBUT 2014, 2017}
b)Using ternary operator write a macro to find out the absolute value of a number{WBUT}
c)Write A program to find out the absolute value of a number using ternary operator

2. what is the Type casting? what is the automatic type conversion? {WBUT }

 Pre increment Post increment 1 Pre increment operator is used to increment variable value by 1 before assigning the value to the variable. Post increment operator is used toincrement variable value by 1 after assigning the value to the variable. 2 Syntax: a = ++x; Syntax: a = x++; 3 Value of i is incremented before assigning it to variable i. Value of i is incremented after assigning it to variable i. 4 5 Example Pre-increment unary operator: ++i; //it is equivalents to the i=i+1; or i+=1 ; Programming Code 1: #include int main() { int i=5; printf(“%d\n”,++i); return 0; } Output: 6 Example Post-increment unary operator: ++i; Programming Code 1: #include int main() { int i=5; printf(“%d\n”,i++); return 0; } Output: 5 6

#include<stdio.h>
#include<conio.h>

void main()
{
int num,r;
clrscr();
printf(" Enter a number");
scanf("%d",&num);
r=(num>0)?(num):(-num);
printf("The absolute value of %d is %d",num,r);
getch();
}

Output:
Enter a number 9
The absolute value of 9 is 9

Enter a number -9
The absolute value of -9 is 9

#include<stdio.h>
#include<conio.h>
#define ABSOLUTE(x)X<0?abs(x):y
int main (void)
{
int x,y,result;
printf(“Enter the value of x”);
scanf(“%d”,&x);
result=ABSOLUTE(x);
printf(“The absolute number is %d”, result);
return EXIT_SUCCESS;
}

Typecasting is the way to convert a variable from one datatype to another the datatype.

provide to the facility of mixing different types of variable and constant in expression
in this type of  operation data type of  offer of one operand is converted into data type of another offer and. this is known as type conversion or Type casting.

The mainly two types of Type casting

1) implicity type conversion

char will be converted into int
float Will be converted into int
explicite type conversion
(type)(Expression)
(float)(x+y /2)

2) Automatic type conversion
• In automatic unary conversion all operands of type char and short will be converted into int Before any operation.
• Some compilers convert all float operants to double Before any operation

Automatic binary conversion
•  The rules for automatic binary conversion are as follow
•  If one operand is long double than the other will be converted to long double and the result     will be long double.
•  Therwise if one operand is double than the other will be converted into double and the result   will be double.
•  Otherwise, if one operand is float  then other will be converted to float and the result will be float
•  Otherwise,  if one operand is unsigned  long int then other will be converted to unsigned long int  and the result will be unsigned lo ng int
• Otherwise, if one operand is long int and other is unsigned int then
• If long int can represent all the value of unsigned int then unsigned int will be converted into long int and result will be long int
• Elss,  both the  operand will be converted to unsigned long int and the result will be unsigned long int.