-
Notifications
You must be signed in to change notification settings - Fork 0
/
typecasting
56 lines (41 loc) · 1.63 KB
/
typecasting
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
48
49
50
51
52
53
54
55
56
#include <iostream>
using namespace std;
int c = 45; //global variable
int main() {
// // *************Build in Data types****************
// int a,b,c;
// cout << "enter the value of a"<<endl;
// cin>>a;
// cout << "enter the value of b"<<endl;
// cin>>b;
// c= a+b;
// cout << " the value of local variable c is "<<c<<endl;
// cout << " the value of global variavle c is "<<::c<<endl;
// ************* Float, double and long double Literals****************
// float d = 45.6F;
// long int e = 55L;
// cout<<" the size of float is "<<sizeof(45.6)<<endl;
// cout<<" the size of float is "<<sizeof(45.6f)<<endl;
// cout<<" the size of float is "<<sizeof(45.6F)<<endl;
// cout<<" the size of float is "<<sizeof(55)<<endl;
// cout<<" the size of float is "<<sizeof(55l)<<endl;
// cout<<" the size of float is "<<sizeof(55L)<<endl;
// *************Reference Variables****************
// Rohan Das----> Monty -----> Rohu ------> Dangerous Coder
// float x = 455;
// float & y = x;
// cout<<x<<endl;
// cout<<y<<endl;
// *************Typecasting****************
int a = 45;
float b = 45.46;
cout<<"the value of a is "<<(float)a<<endl;
cout<<"the value of a is "<<float(a)<<endl;
cout<<"the value of b is "<<int(a)<<endl;
cout<<"the value of b is "<<(int)a<<endl;
int c = int(b);
cout<<"the value of a + b is "<<a+b<<endl;
cout<<"the value of a + b is "<<a+(int)b<<endl;
cout<<"the value of a + b is "<<float(a)+b<<endl;
return 0;
}