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
