-
Notifications
You must be signed in to change notification settings - Fork 0
/
size_of_variable.cpp
65 lines (47 loc) · 1.02 KB
/
size_of_variable.cpp
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
57
58
59
60
61
62
63
64
65
//{ Driver Code Starts
//Initial Template for C++
#include<bits/stdc++.h>
using namespace std;
template <typename T>
// } Driver Code Ends
// Refer Template in C++ track for more details
// on template
int sizeOfValue(T value){
// You are given a variable value
// of unknown type.
// find the size of the value.
// complete the code
int ans =sizeof(value);
return ans;
}
//{ Driver Code Starts.
int main()
{
int t;
cin>>t;
while(t--)
{
int c;
cin>>c;
if(c==1)
{
double a;
cin>>a;
cout<<sizeOfValue<double>(a);
}
else if(c==2)
{
int a;
cin>>a;
cout<<sizeOfValue<int>(a);
}
else
{
char a;
cin>>a;
cout<<sizeOfValue<char>(a);
}
cout<<endl;
}
}
// } Driver Code Ends