c++里面有沒有什么辦法做到 判斷某個給定的未知數是double類型還是int類型 呢?
如果只是double和int, 可以用sizeof
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <iostream>
using
namespace
std;
#include <stdlib.h>
int
main()
{
double
a;
double
b;
float
c = 3.0;
b=1, a=b+5/2;
cout <<
sizeof
a << endl;
cout <<
sizeof
b << endl;
cout <<
sizeof
c<< endl;
cout <<
sizeof
3 << endl;
cout <<
sizeof
3.0 << endl;
cout <<
sizeof
((
int
)3) << endl;
cout <<
sizeof
((
long
)3) << endl;
cout <<
sizeof
((
float
)3) << endl;
cout <<
sizeof
((
double
)3) << endl;
system
(
"pause"
);
return
0;
}
|
c++里面有沒有什么辦法做到 判斷某個給定的未知數是int類型,long類型,還是float類型 呢?
貌似做不到
參考
--------------------------------
1.sizeof 運算符 - cppreference.com
2.若已定義x和y為double類型,則表達式:x=1,y=x+3/2的值是______.(A、1B、2C、2.0D、2.5_百度作業幫
== 以上 2017/7/7 下午3:00:20