-
Notifications
You must be signed in to change notification settings - Fork 20
/
typecast.c
47 lines (40 loc) · 1.12 KB
/
typecast.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
int main()
{
//1. casting int to float
// int num=50;
// float f;
// f=num;//implicit type casting
// // ////or
// f=(float)num;//compiler implicitly doing this to num
// printf("the value of f is %f\n",f);
////2. casting float to int
// float f2=35.76;
// int num2;
// num2=f2;
// // //// or
// num2=(int)f2; //compiler automatically doing this
// printf("the value of num2 is %d\n",num2);
// //// 3.casting int to char
// int num3=98;
// char ch2;
// ch2=num3;
// // ch2=(char)num3;//compiler automatically doing this
// printf("the value of ch2 is %c\n",ch2);
// // //4.casting char to int
// char ch3='B';
// int num4;
// num4=ch3;
// //num4=(int)ch3;//compiler automatically doing this
// printf("the value of num4 is %d\n",num4);
// printf(" %c \n",68);
// printf(" %c \n",50);
// printf(" %d \n",'C');
char ch='1',ch2='1',ch3;
ch3=ch+ch2;
printf("%c",ch3);
return 0;
}
// A-65 + 26 = 91-1 => 90 (Z)
// a-97 + 25 => z
// 0-48 + 9 => 57(9)